Bitwise Operations Playground

AND, OR, XOR

You can change the operation by clicking/pressing on the operator.

110000
011011

010000

We do the AND operation, bit by bit, on the binary representation of 48, 27. Use the controls below to step through the bits. The corresponding truth table is shown below.

ABA & B
000
010
100
111

NOT

~
not
10111
01000

I want to mention a point which might cause confusion while getting started with bitwise NOT operation.
In a bitwise NOT operation, all the leading zeros will be flipped to a 1. This means varying number of leading zeros produce different outputs from the same input.
Use the buttons below to add/remove leading zeros to see what outputs are produced. You can see the output value (40) changes even though the input value (23) doesn't.

010111
101000
1 leading zeros

SHIFTS

The shift is done on binary representation of the first operand. The second operand is the number of positions to be shifted. The bits can be shifted to either left or right.

You can change the operation by pressing on the operator.

affect the output of the shift when the bits overflow.
Supports 6 to 12.

LOGICAL SHIFT

0000011011
0000000110

The 2 right-most digits are shifted off.
The vacant bits on the left side are filled with 0.

Usually, in most programming languages (including C/C++, Java, JavaScript and Python), only logical shifts are available.

Also note that in Python 3, the numbers are stored using arbitrary precision, which can be thought of infinite amount of zeros in front of the number.

CIRCULAR SHIFT

0000011011
1100000110

The vacant bits on the left side are filled with the bits pushed off from the right side.

There is also a third type of bitwise shift: Arithmetic Shift. I have excluded it here, as it is analogus to logical shift when dealing with unsigned integers.