What are binary (bitwise) operations?
Bitwise operations work directly on the binary representation of integers, one bit at a time. AND (A & B) sets a bit to 1 only if both inputs have 1 there — used for bit masking. OR (A | B) sets a bit if either input is 1 — used to set flags. XOR (A ^ B) sets a bit only when the inputs differ — used in encryption and parity. NOT (~A) flips all bits — produces the one's complement. Left shift (<<) multiplies by powers of two; right shift (>>) divides. These operations are foundational in low-level programming, networking, graphics, and cryptography.
How to use this tool
- 1 Enter values in Input A and Input B. Choose the input format (decimal, hex, binary, or octal).
- 2 Click an operation button — AND, OR, XOR, NOT, NAND, NOR, XNOR, <<, >>, or >>>.
- 3 For shift operations (<<, >>, >>>), set the number of bits to shift.
- 4 The result is displayed in decimal, hex, binary, and octal.
- 5 The 32-bit grid shows each bit: teal squares are 1, grey squares are 0.
Frequently asked questions
Why does NOT produce a large negative number?
JavaScript represents integers as signed 32-bit values internally. NOT flips all 32 bits, including the sign bit, so ~0 = -1 and ~1 = -2. The 32-bit grid shows the actual bit pattern, which makes this intuitive.
What is the difference between >> and >>>?
>> is a signed right shift — it copies the sign bit (arithmetic shift), so negative numbers stay negative. >>> is an unsigned right shift — it always fills with 0 from the left, making the result non-negative. For positive inputs they behave identically.
What is NAND and NOR?
NAND is NOT of AND (the opposite of AND) and NOR is NOT of OR. They are logically complete — any other gate can be built from NAND alone, or NOR alone. They appear in digital circuit design and as shorthand.
Can I use hex or binary input?
Yes. Use the input format selector to switch between decimal, hex (0x…), binary (0b…), and octal. Each number is parsed in the selected base.
Are values treated as 32-bit integers?
Yes — JavaScript coerces bitwise operands to signed 32-bit integers. Values larger than 2^31 - 1 or smaller than -2^31 will be truncated. This matches the behaviour of C/Java int.