Skip to content

Instantly share code, notes, and snippets.

@reportbase
Created March 22, 2015 21:15
Show Gist options
  • Save reportbase/51340227f0c4f10e715d to your computer and use it in GitHub Desktop.
Save reportbase/51340227f0c4f10e715d to your computer and use it in GitHub Desktop.
is bit set?
inline int is_bit_set(unsigned int val, int n)
{
static unsigned int mask[] =
{
1, //0x1 << 0
2, //0x1 << 1
4, //0x1 << 2
8, //0x1 << 3
16, //0x1 << 4
32, //0x1 << 5
64, //0x1 << 6
128, //0x1 << 7
256, //0x1 << 8
512, //0x1 << 9
1024, //0x1 << 10
2048, //0x1 << 11
4096, //0x1 << 12
8192, //0x1 << 13
16384, //0x1 << 14
32768, //0x1 << 15
65536, //0x1 << 16
};
return val & mask[n];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment