Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- &
- 001101 //pos = 3
- ^
- 1 << pos
- 001000
- ~
- 110111
- &
- 001101
- 000101
- bit & ~(1 << pos);
- ************************************************
- |
- 001101 //pos = 4
- ^
- 1 << pos
- 010000
- |
- 001101
- 011101
- bit | (1 << pos);
- ************************************************
- ^
- 001101 //pos = 3
- ^
- 1 << pos
- 001000
- ^
- 001101
- 000101 // pos = 3
- ^
- 1 << pos
- 001000
- ^
- 000101
- 001101
- bit ^ (1 << pos);
- ************************************************
- //bit is the number, pos is the position to be changed
- Change bit from 0 to 1: bit | (1 << pos);
- Change bit from 1 to 0: bit & ~(1 << pos);
- Invert bit at position, regardless of value: bit ^ (1 << pos);
Advertisement
Add Comment
Please, Sign In to add comment