B
Bit Twiddler
I have a home grown bit vector and I keep oscillating between what I use
access individual bits.
For example, is is better to do this:
const int BIT_1 = 1;
const int BIT_2 = 2;
....
int my_bits;
// Set bit 1
my_bits |= BIT_1;
Or, should I create an enum
enum BitPos
{
Bit1 = 1,
Bit2 = 2,
....
}
// Set bit 1
my_bits |= (int)BitPos.Bit1;
--------------------------------------------------------
The explicit cast bothers me... any opinions as to how you might do this
would be appreciated!
-Reed
access individual bits.
For example, is is better to do this:
const int BIT_1 = 1;
const int BIT_2 = 2;
....
int my_bits;
// Set bit 1
my_bits |= BIT_1;
Or, should I create an enum
enum BitPos
{
Bit1 = 1,
Bit2 = 2,
....
}
// Set bit 1
my_bits |= (int)BitPos.Bit1;
--------------------------------------------------------
The explicit cast bothers me... any opinions as to how you might do this
would be appreciated!
-Reed