Bitwise Calculator

Twelve bitwise operations — AND, OR, XOR, NOT, NAND, NOR, XNOR, logical and arithmetic shifts, and bit rotations — over 8, 16, 32, or 64-bit widths. BigInt math throughout, so 64-bit values stay exact and the unsigned 64-bit range (018,446,744,073,709,551,615) doesn’t lose precision. Live bit-grid with per-bit color, popcount, leading / trailing zero counts, and a signed two’s-complement view. Copy buttons for every output form. All math runs in your browser — nothing is uploaded.

Result

Decimal
Hex
Binary
Octal
Signed (two’s-complement)

Bit grid most-significant on the left

1 (set) 0 (clear) Hover any bit to see its index, byte, and decimal weight.

Statistics

Popcount
Leading zeros
Trailing zeros
High bit set?
A & B masked?
How the operations map to the bit width
  • AND (&), OR (|), XOR (^): standard bitwise. Both operands are first masked to [0, 2^width), so a value that doesn’t fit gets its upper bits dropped. The page shows a warning.
  • NOT (~): flips every bit in the chosen width. ~x & mask.
  • NAND / NOR / XNOR: the AND / OR / XOR result with every bit flipped. Same masking rules.
  • SHL (<<): shift left, zero-fill from the right. Bits shifted past the high end are dropped. Shift count >= width zeroes the value.
  • SHR (>>): logical shift right, zero-fill from the left.
  • SAR (>>>): arithmetic shift right — replicates the high bit so a negative two’s-complement value stays negative. A shift by width yields 0 if the high bit is clear, or all-ones if it’s set.
  • ROL / ROR: rotate left / right. Bits that fall off one end re-enter on the other. Rotate by width is identity.
  • Bit width selector: changes the mask for inputs and the number of digits in the hex / bin / oct output. Switch to 64-bit for unsigned 64-bit values; everything below that gets clamped to 32-bit Number precision.
  • BigInt math: all internal arithmetic is on BigInt, so the 64-bit range stays exact even for values above 2^53.
  • Literal input: the A / B boxes accept decimal (42), hex (0x2A), octal (0o52), binary (0b101010), and JS literal underscores (1_000_000).