I’m trying to do simple bit operations on a ‘char’ variable;
I would like to define 5 constants.
const int a = 0;
const int b = 1;
const int c = 2;
const int d = 3;
const int e = 4;
When I try to set more than one bit of the char, all bits apparently up to the set bit a read as set…here is code I use to set and read bits of the char var:
char var = 0;
var |= c;
var|= d;
BOOL set = false;
if(var & b)
set = true; // reads true
if(var & c)
set = true; // also reads true
if(var & d)
set = true; // also reads true
I read an incomplete thread that says that the operation to set bits may be different for x86…the system I’m using…is that the case here?
You’re cutting into your other “bits”‘ space. Examining a couple gives us:
To get around this, make each one represent a new bit position:
You should consider not using 0 if there’s a possibility of no bits being set meaning something different, too. The main application for this is to set and check flags, and no flags set definitely shows independence.