Guest User

Untitled

a guest
May 22nd, 2018
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.45 KB | None | 0 0
  1. | is used to set a certain bit to 1
  2.  
  3. & is used to test or clear a certain bit
  4.  
  5. Set a bit (where n is the bit number, and 0 is the least significant bit):
  6.  
  7. unsigned char a |= (1 << n);
  8.  
  9. Clear a bit:
  10.  
  11. unsigned char b &= ~(1 << n);
  12.  
  13. Toggle a bit:
  14.  
  15. unsigned char c ^= (1 << n);
  16.  
  17. Test a bit:
  18.  
  19. unsigned char e = d & (1 << n);
  20.  
  21. Take the case of your list for example:
  22.  
  23. x | 2 is used to set bit 1 of x to 1
  24.  
  25. x & 1 is used to test if bit 0 of x is 1 or 0
Add Comment
Please, Sign In to add comment