piapia123
en

Bitwise Calculator

Convert

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

Ten bitwise operations share one tool because their inputs and outputs are identical and only the operator differs — split across ten pages the content would be near-identical and competing for the same searches. Why not use the language’s own bitwise operators? Because they coerce to 32-bit signed integers: `1 << 31` gives `-2147483648`, `0xFFFFFFFF` reads as `-1`, and anything past 32 bits is silently truncated, with no error raised. The values people bring to a bitwise tool are usually 64-bit masks, hash fragments and integers unpacked from UUIDs, and all of those come out wrong. This tool uses BigInt throughout: `<<` shifts as far as you like and `&` never turns into a negative number. Bit width controls reduction and display. At 32 bits the operands are reduced modulo 2³² first (so `-1` becomes all ones, which is what two’s complement means), and results are shown padded to 32 bits. Choosing Unlimited skips both, so `~0` is `-1` — mathematically correct, but not what someone working with masks wants, which is why 32 is the default.

Features

  • Ten operations: AND, OR, XOR, XNOR, NAND, NOR, NOT, left shift, right shift and bit reversal
  • Every result shows decimal, binary, hex and bit length, each on a copyable row
  • Inputs accept 0b / 0o / 0x prefixes and decimal; underscores and spaces work as separators
  • Bit width of 8, 16, 32 or 64, or Unlimited for arbitrary precision
  • When a width is set, operands are reduced first: `-1` at 8 bits becomes 255, as expected
  • Left shift never overflows into a negative number (as `1 << 31` does in JavaScript)
  • One operand per line, so a whole list can be run against the same mask
  • Exact on 64-bit masks and very large integers — nothing goes through floating point

How to use

  1. Paste the operands, one per line (0b / 0o / 0x prefixes are understood)
  2. Choose the operation and bit width, then fill in the second operand
  3. The result updates as you type; copy a single value from its row

FAQ

Why is the result different from what my code produces?
Most likely because you are using your language’s bitwise operators, which work on 32-bit signed integers. Three typical differences: `1 << 31` is `-2147483648` there and `2147483648` here; `0xFFFFFFFF` reads as `-1` there; and operands past 32 bits are silently truncated. Setting the width to Unlimited shows the untruncated result, while 32 bits matches the language behaviour apart from being displayed unsigned.
Which bit width should I choose?
Whichever matches your target environment. C ints or JavaScript bitwise work: 32 bits. uint8 arrays, RGB channels, protocol fields: 8 or 16 bits. 64-bit masks and hashes: 64 bits. Just the mathematical answer: Unlimited. The width only affects reduction and zero-padding; it never changes whether the operation itself is right.
Is the right shift arithmetic or logical?
Logical (unsigned). Once a width is set the operands have been reduced, so they are all non-negative and there is no sign to extend. Hence `0xFFFFFFFF >> 4` gives `0x0FFFFFFF`. If you need an arithmetic shift (keeping the sign bit of a negative value), set the width to Unlimited, where BigInt’s `>>` is arithmetic for negative numbers.

Related tools