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
- x & (x - 1) clears the lowest set bit. x & -x isolates it.
- A number is a power of two when it has exactly one set bit.
- XOR of a number with itself is 0, a handy trick in interview problems.
- Use 0x for hex and 0b for binary numbers.
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.
Watch 10 sorting algorithms animate step by step with live counters and pseudocode, or race them on the same input.
CS Labs & CodingTOP PICKGraph Algorithm VisualizerTOP PICKDraw your own graph and watch BFS, DFS, Dijkstra, Bellman-Ford, Prim, Kruskal, topological sort and more run step by step, with the queue, the distance table and the reason for every move.
Big-O Estimator from TimingsTime your code on a few input sizes, paste the numbers, and see which growth rate fits best.
OPEN →