Skip to content

Instantly share code, notes, and snippets.

@nall
Created January 23, 2010 21:41
Show Gist options
  • Save nall/284814 to your computer and use it in GitHub Desktop.
Save nall/284814 to your computer and use it in GitHub Desktop.
#ifdef DEBUG
BOOL GET_BIT(uint32_t value, uint32_t bit)
{
assert(bit < (sizeof(value) * 8));
return ((value >> bit) & 1);
}
uint32_t SET_BIT(uint32_t value, uint32_t bit, BOOL bitValue)
{
assert(bit < (sizeof(value) * 8));
assert(bitValue == 1 || bitValue == 0);
const uint32_t mask = (bitValue << bit);
return ((value & ~mask) | mask);
}
#else // DEBUG
#define GET_BIT(value, bit) (((value) >> (bit)) & 1)
#define SET_BIT(value, bit, bitValue) ((value & ~(bitValue << bit)) | (bitValue << bit))
#endif // DEBUG
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment