Parsing a DWORD
OK, you know how you can OR together bits like THIS | THAT | THEM in like a UINT or DWORD (might be anything, but those are the ones I see most often)? Well, what''s the technique used to extract the bits from the DWORD? Like if I wanted to create a file object that had four options, READ, WRITE, BINARY, APPEND.
Say the person created a file with CreateFile(READ | WRITE | BINARY) meaning he wanted binary acess w/ read and write enabled. How would I extract the bits so I could tell what the programmer wants? Thx.
==============================
"Need more eeenput..."
- #5, "Short Circuit"
==============================
Drew Sikora
Executive Producer
GameDev.net
You have to use &. See?
Regards,
Jumpster
EDIT: Source Blocks didn't work. How about CODE blocks...
Edited by - Jumpster on November 12, 2000 9:51:10 AM
#define THIS 1#define THAT 2#define THEM 4// Is the THIS bit set...?result = (Value & THIS) ? true : false;
Regards,
Jumpster
EDIT: Source Blocks didn't work. How about CODE blocks...
Edited by - Jumpster on November 12, 2000 9:51:10 AM
Regards,JumpsterSemper Fi
damnit! And i just wrote a program for it... DOH
I think im gonna post my program anyway!
=======================
Game project(s):
www.fiend.cjb.net
I think im gonna post my program anyway!
#include #define WRITE 0x00000000000000000000000000000001#define READ 0x00000000000000000000000000000010#define BINARY 0x00000000000000000000000000000100#define GURGEL 0x00000000000000000000000000001000int main(){ unsigned int flags; flags=GURGEL; //sets flag to GURGEL flags=flags|READ|WRITE; //keeps old flags and puts READ and WRITE on... if(flags&WRITE) cout << "Write flag on" << endl; if(flags&READ) cout << "Read flag on" << endl; if(flags&BINARY) cout << "Binary flag on" << endl; if(flags&GURGEL) cout << "Gurgel flag on" << endl; return 0;}
=======================
Game project(s):
www.fiend.cjb.net
=======================Game project(s):www.fiend.cjb.net
cool - thanks!
==============================
"Need more eeenput..."
- #5, "Short Circuit"
==============================
==============================
"Need more eeenput..."
- #5, "Short Circuit"
==============================
Drew Sikora
Executive Producer
GameDev.net
Jonatan, you defined your constants as binary numbers, not hexidecimal
0x1
0x2
0x4
0x8
0x10
0x20
0x40
0x80
0x100
...
0x80000000
will use every bit available... don't need all those preceeding zeros either...
Edited by - Magmai Kai Holmlor on November 12, 2000 3:25:43 PM
0x1
0x2
0x4
0x8
0x10
0x20
0x40
0x80
0x100
...
0x80000000
will use every bit available... don't need all those preceeding zeros either...
Edited by - Magmai Kai Holmlor on November 12, 2000 3:25:43 PM
- The trade-off between price and quality does not exist in Japan. Rather, the idea that high quality brings on cost reduction is widely accepted.-- Tajima & Matsubara
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement