Common Bit Manipulation Macros in C Language
1. Set a specific bit to 1: Macro #define setbit(x,y) x|=(1<<y) – Sets the y-th bit to 1.2. Set a specific bit to 0: Macro #define clrbit(x,y) x&=~(1<<y) – Sets the y-th bit to 0.3. Toggle a specific bit: Macro #define reversebit(x,y) x^=(1<<y) – Toggles the y-th bit. Note: XOR results in 0 for the … Read more