Bit & Bytes Confusion / Troubles
Well, I'm about to pull my hair out on this. So I figured I'd post for help before I cause some premature baldness.
I'm fairly new to C# and have run into this problem trying to get info out of a int byte that I get returned.
Here is what is stated in the lib that I'm working with.
The first three bits represent a single value, not flags. For example Auction (0x05) is not a combination of OwnedByOther (0x01) and ForSale(0x04). However, the BorderWest and BorderSouth values are bit flags that get attached to the value stored in the first three bits. Bits four, five, and six are unused
public enum OverlayType : byte
{
Public = 0,
OwnedByOther = 1,
OwnedByGroup = 2,
OwnedBySelf = 3,
ForSale = 4,
Auction = 5,
BorderWest = 64,
BorderSouth = 128
}
Guest UserPosted Feb 11, 2009, 11:36 AM
byte b = 0; // assign your value here
if ((b & (byte)OverlayType.Auction) == (byte)OverlayType.Auction)
{
// do auction stuff
}
The casts are necessary because OverlayType is considered a separate type, even though the underlying datatype is the same.