Skip to content

Instantly share code, notes, and snippets.

@brockers
Last active January 8, 2019 19:16
Show Gist options
  • Save brockers/e946c46f8a4b922c76582e93b5c408b7 to your computer and use it in GitHub Desktop.
Save brockers/e946c46f8a4b922c76582e93b5c408b7 to your computer and use it in GitHub Desktop.
Quick lookup cheatsheet to demonstrate binary operators in C/C++

Binary Operators

Reference Values

128 64 32 16 8 4 2 1 VALUE
0 0 1 1 1 1 0 0 60
0 0 0 0 1 1 0 1 13

Dual Argument Operators

Type Argument Result Value
and 60 & 13 0000 1100 12
or 60 | 13 0011 1101 61
xor 60 ^ 13 0011 0001 49

Single Argument Operators

Type Argument Result Value
One's Compliment ~60 1100 0011 195

Shift Operators (move bits left or right by given number)

Type Argument Result Value
Right Shift 60 >> 1 1001 1110 29
Left Shift 60 << 2 1111 0000 240

Useful Examples

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment