Effectively you just want to check a given value against x..
int value = X; //user input, or saved value
int check = 1<<3; //third to last bit 0x0...001000
bool hasCheck = (value & check == check);
I am pretty sure you can do something like the following...
[Flags]
public enum MyOptions : int {
None= 0,
First= 1,
Second= 1<<1,
Third= 1<<2
}
public bool HasOption(MyOptions value, MyOptions check) {
return (value & check == check);
}
On 10/13/2008 11:10 AM, bob wrote:
Hi,
Having trouble determining if bit n in a byte is on or off.
Seem to remember being able to do this with the logical And operator
something like if (2 & mybyte) { do something}
Maybe I am dreaming of VB days.
Is there a succint way of doing this?
thanks
Bob
--
Michael J. Ryan - tracker1(at)theroughnecks(dot)net -
www.theroughnecks.net
icq: 4935386 - AIM/AOL: azTracker1 - Y!: azTracker1 - MSN/Win: (email)
.... B5: The mind sees what it needs to see. The soul sees what the soul sees.