Skip to content

Instantly share code, notes, and snippets.

@marabesi
Last active August 29, 2015 14:16
Show Gist options
  • Save marabesi/d4252c48424bf212fdc3 to your computer and use it in GitHub Desktop.
Save marabesi/d4252c48424bf212fdc3 to your computer and use it in GitHub Desktop.
Example how to use the bitwise operators in a easy way
128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
1 | 1 | 1 | 1 | 1 | 1 | 1 | 1 | = 255 // just sum all the possible bit values in the table
| | | | | | | |
0 | 0 | 0 | 0 | 1 | 0 | 1 | 0 | = 10 // Representation of the 10 in bit
1 | 1 | 0 | 0 | 0 | 0 | 0 | 0 | = 192 // Representation of the 192 in bit
AND (&) Operator (7 & 9) The bits must be active in either rows
0 | 0 | 0 | 0 | 0 | 1 | 1 | 1 | = 7
0 | 0 | 0 | 0 | 1 | 0 | 0 | 1 | = 9
0 | 0 | 0 | 0 | 0 | 0 | 0 | 1 | = 1 // Result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment