Last active
August 29, 2015 14:16
-
-
Save marabesi/d4252c48424bf212fdc3 to your computer and use it in GitHub Desktop.
Example how to use the bitwise operators in a easy way
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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