Work out bit masks, flags, and shifts without second-guessing the result. Choose a width, type two operands in hex, binary, octal, or decimal, and pick AND, OR, XOR, NOT, NAND, NOR, XNOR, a logical or arithmetic shift, or a rotate. Both operands are drawn as clickable bit grids and the result as a read-only one, with the index under each byte, so you can toggle a bit and watch the hex and two's complement values update. The math runs on BigInt, which means 64-bit values and shifts by the full width come out exactly instead of being truncated to 32 bits the way JavaScript's own operators do. Nothing you type leaves your browser.
To convert a single value between bases, the number base converter handles signed and unsigned widths. The chmod calculator is the same idea applied to Unix permission bits, the XOR cipher runs XOR across whole strings and keys, and the subnet calculator shows netmasks as the AND masks they really are.
For the everyday patterns behind the operators (set, clear, toggle and test a flag, power-of-two checks, packing fields with shifts, and JavaScript's 32-bit traps), read bit masks and flags.
Frequently asked questions
What is two's complement, and why does 0xFF read as -1 at 8 bits?
Two's complement is how nearly every CPU stores signed integers. The top bit carries a weight of minus 2 to the power of (width minus 1) instead of plus, so at 8 bits the pattern 1111 1111 is -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1. The same bits read as 255 if you treat them as unsigned, which is why the result panel shows both. Negating a value is "invert all bits, then add 1": 0000 0001 becomes 1111 1111. The signed range at 8 bits is -128 to 127.
When do I use AND, OR, and XOR? A quick cheat sheet.
AND with a mask keeps only the bits you care about and clears the rest: value & 0x0F isolates the low nibble, and value & 1 tests the lowest bit. OR with a mask sets bits without touching the others: flags | 0x04 turns on bit 2. XOR with a mask toggles bits: flags ^ 0x04 flips bit 2, and XOR with all ones is the same as NOT. To clear a bit, AND with the inverted mask: flags & ~0x04. XOR of a value with itself is always 0, which is why it shows up in swap tricks and checksums.
Why does 1 << 32 give 1 in JavaScript, and what is >>>?
JavaScript's bitwise operators convert their operands to 32-bit signed integers and mask the shift count to 5 bits, so a shift by 32 is really a shift by 32 mod 32 = 0. That makes 1 << 32 equal 1. The same operators make 0xFFFFFFFF | 0 come out as -1, because bit 31 is the sign. The >>> operator is the unsigned (logical) right shift: it fills with zeros and returns a non-negative result, so x >>> 0 is the usual idiom for reading a value as an unsigned 32-bit integer. This calculator uses BigInt instead, so shifts by the full width give 0 and 64-bit values stay exact.
What is the difference between a logical and an arithmetic right shift?
Both move every bit toward the least significant end and drop the bits that fall off. They differ in what fills the vacated high bits. A logical shift (SHR, >>> in JavaScript, >> on unsigned types in C) fills with zeros, so 1000 0000 >> 1 becomes 0100 0000: 128 becomes 64. An arithmetic shift (SAR, >> on signed types) copies the sign bit, so 1000 0000 becomes 1100 0000: -128 becomes -64, preserving the sign like a divide by two that rounds toward negative infinity. Pick SAR for signed values where you want division semantics, and SHR for raw bit fields or unsigned numbers.
What are rotate left and rotate right used for?
A rotate (ROL/ROR, or circular shift) is a shift where the bits that fall off one end come back in at the other, so nothing is lost and rotating by the full width returns the original value. Rotates are a building block of hash functions and ciphers: SHA-256 uses right rotates by 2, 13, and 22 bits, ChaCha20 uses left rotates by 16, 12, 8, and 7, and the ARX (add-rotate-xor) cipher family is named for them. Most CPUs have a rotate instruction, but C and JavaScript do not have a rotate operator, so it is written as (x << n) | (x >>> (w - n)).