Bitwise calculator

AND, OR, XOR, NOT, NAND, NOR and shifts on whole numbers of any size, with the bits aligned in a grid.

How it works

Bitwise operations work on each bit position separately, with no carries: AND keeps a 1 only where both numbers have one (useful for masks: $x \mathbin{\&} 255$ keeps the lowest byte), OR sets bits, XOR flips the bits where the other number has a 1. NOT flips every bit, which only makes sense with a fixed width: in 8 bits, NOT 01011010 is 10100101.

A shift moves all bits. Shifting left by $k$ multiplies by $2^k$ (bits that leave a fixed width are lost); shifting right divides by $2^k$ rounding down. For negative numbers in two’s complement there are two right shifts: the arithmetic shift copies the sign bit and keeps the number negative, the logical shift brings in zeros.

These operations are the building blocks of ciphers and hash functions (SHA-256 is nothing but additions, rotations, AND, XOR and NOT on 32-bit words), and of fast code everywhere. Here the numbers may be as large as you like; give a width to work modulo $2^n$.

Everything is calculated in your browser. Nothing you type leaves your device.