Created
March 22, 2015 21:15
-
-
Save reportbase/51340227f0c4f10e715d to your computer and use it in GitHub Desktop.
is bit set?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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