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.

You can change the operation by pressing on the operator.

LOGICAL SHIFT

11011
01101

The right-most digit is shifted off.
The vacant bit on the left side is filled with 0.

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

CIRCULAR SHIFT

11011
11101

The vacant bit on the left side is filled with the bit 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.