Bitwise Playground

Try AND, OR, XOR, NOT and shifts on two numbers and see binary, hex, signed and two's complement forms.

How it works

Type two numbers and choose a bit width. The tool shows A in binary, the signed and unsigned values, and the result of AND, OR, XOR, NOT and shifts, each in binary and hex. Negative numbers are stored in two's complement.

The formula

two's complement of x in n bits = 2^n - x
A << k = A x 2^k (bits that fall off the left are lost)
A >> k logical = fill with 0, arithmetic = copy the sign bit

Worked example

12 in 8 bits is 0000 1100. NOT 12 is 1111 0011, which is 243 unsigned and -13 signed. 12 << 2 is 0011 0000 = 48.

Good to know

Common questions

What is two's complement?
The way computers store negative numbers. Flip all bits and add 1. It makes addition work the same for signed and unsigned numbers.
Why does the signed value differ from the unsigned one?
The top bit means negative in signed form. 1111 1111 is 255 unsigned and -1 signed.
What is the difference between logical and arithmetic shift?
A logical right shift fills with zeros. An arithmetic right shift copies the sign bit so negative numbers stay negative.

More in CS Labs & Coding.