Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- | is used to set a certain bit to 1
- & is used to test or clear a certain bit
- Set a bit (where n is the bit number, and 0 is the least significant bit):
- unsigned char a |= (1 << n);
- Clear a bit:
- unsigned char b &= ~(1 << n);
- Toggle a bit:
- unsigned char c ^= (1 << n);
- Test a bit:
- unsigned char e = d & (1 << n);
- Take the case of your list for example:
- x | 2 is used to set bit 1 of x to 1
- x & 1 is used to test if bit 0 of x is 1 or 0
Add Comment
Please, Sign In to add comment