Skip to main content

OTHER · BITWISE

Bitwise Calculator

Perform AND, OR, XOR, NOT, left-shift, and right-shift on any integers at 8/16/32/64-bit widths — with correct two's-complement signed interpretation.

Bit Width
Operation
Operands

Negative values wrap via two's complement

02 Result (8-bit)
Binary
0000 0000
Hex0x0
Octal0o0
Unsigned decimal0
Signed (two's comp.)0

About This Calculator

Perform bitwise operations on integers at any supported bit width (8, 16, 32, or 64 bits). Results show binary, hex, and both unsigned and signed decimal (two's-complement) interpretations. Handles 64-bit values correctly using BigInt — JS bitwise operators silently coerce to 32-bit signed.

How It Works

Enter one or two operands as signed decimal integers (negative values wrap via two's complement for the selected bit width). Choose the operation and bit width; the result is shown in binary, hex, octal, and decimal. The "Signed (two's complement)" row shows the value as a signed integer — if the sign bit is set (value ≥ 2^(width−1)), the signed value is negative.

The Formula

result = (A op B) & mask mask = 2^w − 1 signed = result ≥ 2^(w−1) ? result − 2^w : result

A, B
operands (two's-complement wrapped to bit width)
w
bit width (8, 16, 32, or 64)
mask
width mask, e.g. 0xFF for 8-bit

Frequently Asked Questions

Why does bit width matter for bitwise operations?
JavaScript's native &, |, ^, ~ operators coerce both operands to 32-bit signed integers (ToInt32) before operating. Any value above 2^31 − 1 is silently truncated. This calculator uses BigInt for all widths, eliminating that silent truncation.
What is two's complement?
Two's complement is how computers store signed integers. In w-bit two's complement, a bit pattern v represents a negative number when v ≥ 2^(w−1). The signed value is v − 2^w. For example, 0xFF in 8-bit = 255 unsigned = −1 signed.
How does NOT work in this calculator?
NOT flips every bit in the operand, masked to the selected bit width. NOT 0 in 8-bit = 0xFF (255 unsigned, −1 signed). In JavaScript, ~0 = −1 (unbounded BigInt behaviour); masking to 8 bits gives the correct 0xFF result.