Skip to content

Instantly share code, notes, and snippets.

@rishid
Created December 27, 2012 16:28
Show Gist options
  • Save rishid/4389604 to your computer and use it in GitHub Desktop.
Save rishid/4389604 to your computer and use it in GitHub Desktop.
Great macro for building bitmask in C
#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