Bit Flags and Fancy Math
Over on CF-Talk today, Dennis Powers had a problem with selecting the correct records when dealing with bit flags. I'm a big fan of flags and bitwise math, so I jumped in and helped him out. I had to think about the operations a bit (no pun intended) too long, so I decided to drop myself a note as a refresher.
When dealing with bit flags, here is a handy cheatsheet:
Happy masking!
When dealing with bit flags, here is a handy cheatsheet:
myMask = 1st and 8th flags set (10000001 -> 2^7 + 2^0 -> 129)
myVar & myMask = myMask (All masked flags are set)
myVar & myMask > 0 (At least one masked flag is set)
myVar & myMask = 0 (None of the masked flags are set)
myVar = myMask (All masked flags set, all other flags not set)
Happy masking!
0 TrackBacks
Listed below are links to blogs that reference this entry: Bit Flags and Fancy Math.
TrackBack URL for this entry: http://www.ijeff.com/cgi-sys/cgiwrap/jprice/managed-mt/mt-tb.cgi/7


Leave a comment