Skip to content
ZeroServer.tools

Bitwise Calculator

Compute AND, OR, XOR, NOT, and bit-shift operations with binary and hex output.

Bitwise operations, explained

Bitwise operators work directly on the binary representation of integers. AND keeps only bits that are 1 in both operands, OR keeps any bit set in either, and XOR keeps bits set in exactly one operand. NOT flips every bit (32-bit signed result in JavaScript). Left shift multiplies by powers of 2; right shift divides. These are fundamental to flags, masks, and low-level algorithms.

Related tools: decimal to binary converter, base converter, and the decimal to hex converter.

Built and maintained by Meet Shah · Last updated

What this tool is used for

  • Checking the result of a mask operation against what you expected.
  • Working out which flags a combined value has set.
  • Verifying a shift's result at a specific width.
  • Building a mask from individual bit positions.
  • Confirming an implementation's bitwise logic.

Frequently Asked Questions

Why are the results 32-bit?
Because JavaScript's bitwise operators convert their operands to signed 32-bit integers, and so does this. A value above 2³¹−1 wraps to negative, and anything above 2³² is truncated outright — which is why 1 << 31 is −2147483648 rather than a large positive number.
What is the difference between >> and >>>?
Sign handling. `>>` is an arithmetic shift that copies the sign bit inwards, so −8 >> 1 is −4. `>>>` is a logical shift that fills with zeros, so −8 >>> 1 is 2147483644. Using the wrong one on a value that might be negative is a classic source of impossible-looking numbers.
How do bit flags work?
Each option is one bit, so they combine with OR and are tested with AND: `flags | WRITE` sets it, `flags & WRITE` checks it, and `flags & ~WRITE` clears it. Eight independent booleans then fit in a single byte, which is why file permissions and protocol headers are built this way.
Is shifting really faster than multiplying?
It was, decades ago. Any compiler today turns `x * 2` into a shift when that is faster, and on modern CPUs multiplication is a few cycles anyway. Write the arithmetic you mean — `x << 3` for "times eight" is a micro-optimisation that costs the next reader real time.
What is XOR good for?
Toggling and difference. `x ^ mask` flips exactly the bits set in the mask, and `a ^ b` is zero only when the values are equal — which is why it appears in checksums, in simple ciphers, and in the trick for finding the one unpaired value in a list.

Common errors and gotchas

  • Not fixing the width, which makes NOT and right-shift results undefined.
  • Confusing arithmetic and logical right shift, which differ for negative values.
  • Shifting by more than the width, which is undefined behaviour in several languages.
  • Assuming JavaScript's bitwise operators are 64-bit, when they coerce to 32.
  • Reading a negative result as an error rather than two's complement.

Related Developer Utilities tools

Private & free — this tool runs entirely in your browser.

IndieKitShip your Next.js startup in days.affiliate