Skip to content

Instantly share code, notes, and snippets.

@hallojoe
Last active November 4, 2021 13:03
Show Gist options
  • Save hallojoe/7e0e20222cd82bf7f53316875f86c1c0 to your computer and use it in GitHub Desktop.
Save hallojoe/7e0e20222cd82bf7f53316875f86c1c0 to your computer and use it in GitHub Desktop.
Bitwise in 1010 seconds.

Bitwise

Bitwise in 1010 seconds.

AND &

Return 1 where both are 1:

   bin   dec
   ---------
   0001    1  
 &
   0011    3
      ↓
   0001    1

OR |

Return 1 where one or both are 1:

   bin   dec
   ---------
   0001    1
 |
   0011    3
     ↓↓
   0011    3

XOR ^

Return 1 where either is 1 but not both are 1:

   bin   dec
   ---------
   0001    1
 |
   0011    3
     ↓
   0010    2

LEFT SHIFT <<

Move bits n positions to left:

   bin   dec
   ---------
   0001    1
 <<
   0001    1
       ←
   0010    2

RIGHT SHIFT >>

Move bits n positions to right:

   bin   dec
   ---------
   0001    1
 >>
   0001    1
  →   
   0000    0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment