Created
December 27, 2012 16:28
-
-
Save rishid/4389604 to your computer and use it in GitHub Desktop.
Great macro for building bitmask in C
This file contains 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
#include <stdio.h> | |
#define BITMASK(H,L) ( (2ULL<<(H))-(1ULL<<(L)) ) | |
int main() | |
{ | |
printf("bitmask is %08X\n", BITMASK(4,3)); | |
printf("bitmask is %08X\n", BITMASK(63,0)); | |
printf("bitmask is %08X\n", BITMASK(63,2)); | |
printf("bitmask is %08X\n", BITMASK(31,17)); | |
printf("bitmask is %08X\n", BITMASK(1,0)); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment