iliya87

BitoveOperacii

Mar 26th, 2015
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.67 KB | None | 0 0
  1. &
  2. 001101 //pos = 3
  3. ^
  4. 1 << pos
  5. 001000
  6. ~
  7. 110111
  8. &
  9. 001101
  10. 000101
  11.  
  12. bit & ~(1 << pos);
  13. ************************************************
  14. |
  15. 001101 //pos = 4
  16. ^
  17. 1 << pos
  18. 010000
  19. |
  20. 001101
  21. 011101
  22.  
  23. bit | (1 << pos);
  24. ************************************************
  25. ^
  26. 001101 //pos = 3
  27. ^
  28. 1 << pos
  29. 001000
  30. ^
  31. 001101
  32. 000101 // pos = 3
  33. ^
  34. 1 << pos
  35. 001000
  36. ^
  37. 000101
  38. 001101
  39.  
  40. bit ^ (1 << pos);
  41. ************************************************
  42. //bit is the number, pos is the position to be changed
  43. Change bit from 0 to 1: bit | (1 << pos);
  44. Change bit from 1 to 0: bit & ~(1 << pos);
  45. Invert bit at position, regardless of value: bit ^ (1 << pos);
Advertisement
Add Comment
Please, Sign In to add comment