So
here's normal, base-1 counting on your fingers. In base 1, you
just raise the number of fingers equal to the value you're trying to
represent:
|
![]() |
This is funky base-2 counting on your fingers. Each finger represents a
different value now, so you have to start counting with '1' at your
pinky, then '2' with just your ring finger, and '3=2+1' is pinky and
ring finger together. '4' is a single raised middle finger. Then
'5=4+1' is middle finger and pinky, and so on. Just 10 digits actually
allows you to count all the way to 1023, but we'll ignore the thumbs
and just use 8 fingers, to count up to 255=128+64+32+16 (left hand
palm-up, pinky is 16) +8+4+2+1 (right hand palm-down, pinky is 1).
This is actually somewhat useful for counting--try it! (Note: the numbers four, sixty-four, and especially sixty-eight should not be prominently displayed. Digital binary counting is not recommended in a gang-infested area.) |
![]() |
Input |
Output |
0 |
1 |
1 |
0 |
Name |
C/C++ symbol |
Definition |
Example |
Useful for... |
NOT |
~ |
Output is inverse of input. |
~0=1 ~1=0 |
Building bit masks (~0 is all ones!) Turning bits backwards. Computing negative values. |
AND | & |
Output is 1 only if both inputs are 1. |
0&0=0 0&1=0 1&0=0 1&1=1 |
Zeroing out unwanted parts of an input ("masking"). One-bit multiplication! |
OR |
| |
Output is 1 if either input is 1. |
0|0=0 0|1=1 1|0=1 1|1=1 |
Sticking together parts of input data. |
XOR |
^ |
Output is 1if either input is 1, but not both! |
0|0=0 0|1=1 1|0=1 1|1=0 |
Controlled bitwise inversion: x^y inverts bits of y where x is 1, but leaves them alone where x is 0. |