Wishing I had a cute phrase here.

  • Contact
  • Projects
  • Blog
  • About

Bit Flags and Fancy Math

By Jeffrey Price on February 5, 2008 10:07 PM | Permalink | Comments (0) | TrackBacks (0)
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:

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!

Tags:

  • Bitwise

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

Search

About this Entry

This page contains a single entry by Jeffrey Price published on February 5, 2008 10:07 PM.

Domain Name Resellers was the previous entry in this blog.

New Design is the next entry in this blog.

Find recent content on the main index or look in the archives to find all content.

  • Subscribe to feed Subscribe to this blog's feed
Powered by Movable Type 4.01
Powered by Movable Type Publishing Platform
This blog is licensed under a Creative Commons License.