Bitwise calculator
Apply AND, OR, XOR, NOT and shifts to two numbers and see every bit line up. Enter values in hex, decimal or binary.
| A | 1 | 1 | 0 | 0 | 0 | 1 | 0 | 1 | 0xC5 · 197 |
|---|---|---|---|---|---|---|---|---|---|
| B | 0 | 0 | 0 | 0 | 1 | 1 | 1 | 1 | 0xF · 15 |
| AND | 0 | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 0x5 · 5 |
Masks, flags and shifts
Bitwise operators treat a number as a row of independent switches. Unix permissions are a good example: read = 4 (100), write = 2 (010), execute = 1 (001). 6 & 2 is non-zero, so a file with mode 6 is writable; 4 | 1 = 5 grants read and execute.
The default example, 0xC5 AND 0x0F, keeps only the low four bits (the “low nibble”) and returns 0x05. Change the operation to XOR and the same mask flips those four bits instead.
Questions people ask
What does bitwise AND do?
It compares two numbers bit by bit and outputs 1 only where both bits are 1. It is used to mask: x & 0xFF keeps the lowest 8 bits and clears the rest.
What is the difference between OR and XOR?
OR outputs 1 where either bit is 1 (used to set flags). XOR outputs 1 where the bits differ (used to toggle bits, and in checksums and simple ciphers). XOR-ing a value with itself gives 0.
What does NOT do to a number?
It flips every bit within the chosen width. In 8 bits, NOT 00001111 = 11110000. Read as signed two’s complement, NOT x equals −x − 1.
What do << and >> do?
Left shift moves bits toward the high end and fills with zeros, multiplying by 2 per place. Right shift moves them down, dividing by 2 and discarding the remainder. This calculator uses logical (zero-fill) right shift, like JavaScript’s >>>.