JSONToonPro
Number utility tool

Bitwise Calculator

Perform bitwise operations online: AND, OR, XOR, NAND, NOR, XNOR, NOT, left shift, and right shift. Results are displayed in decimal, binary, hexadecimal, and octal simultaneously, all in your browser with no server calls.

100% client sideInstant resultNo data sent

Operation

Value A (decimal)
bin: 00001100 | hex: C
Value B (decimal)
bin: 00001010 | hex: A
Result: 12 & 10 = 8
Decimal8
Binary00001000
Hexadecimal0x8
Octal0o10

The Bitwise Operators

A bitwise operator ignores the numeric value of its operands and works on their individual binary digits, comparing bit 0 with bit 0, bit 1 with bit 1, and so on down the word. The behaviour of each operator is fully described by a truth table covering the four possible input pairs.

AND, OR, XOR

AND produces a 1 only when both input bits are 1, which makes it the natural tool for masking. OR produces a 1 when either bit is 1, which makes it the tool for setting bits. XOR (exclusive or) produces a 1 only when the two bits differ, which makes it the tool for toggling and for cheap reversible transformations.

ABA AND BA OR BA XOR B
00000
01011
10011
11110

NAND, NOR, XNOR

These are the negated forms, the outputs of AND, OR, and XOR with every bit flipped. NAND and NOR matter in hardware because either one alone is functionally complete: any logic circuit whatsoever can be built from nothing but NAND gates, which is why they are the cheapest primitive to fabricate. XNOR outputs 1 when the bits match, so it is an equality test at the bit level.

ABA NAND BA NOR BA XNOR B
00111
01100
10100
11001

NOT

NOT is the only unary operator here. It inverts every bit of its single operand, turning each 1 into a 0 and each 0 into a 1.

ANOT A
01
10

Left Shift and Right Shift

Shifting slides every bit sideways by a given number of positions. Shifting left by n positions multiplies the value by 2 to the power n, filling the vacated low bits with zeros. Shifting right by n positions divides by 2 to the power n and discards whatever falls off the right hand end, so it always rounds toward zero rather than rounding to nearest.

5 << 2   00000101 -> 00010100  5 x 4 = 20
20 >> 2  00010100 -> 00000101  20 / 4 = 5
7 >> 1   00000111 -> 00000011  7 / 2 = 3, remainder discarded

Worked Examples

Write both operands in binary, line them up, and apply the operator column by column. Using 12 (binary 1100) and 10 (binary 1010):

12 AND 10  1100 AND 1010 = 1000 = 8
12 OR  10  1100 OR  1010 = 1110 = 14
12 XOR 10  1100 XOR 1010 = 0110 = 6
5 << 2       101 shifted left 2 = 10100 = 20
20 >> 2     10100 shifted right 2 = 101 = 5

What Bitwise Operations Are Used For

Bit flags and permission masks

A single integer can carry dozens of independent booleans, one per bit. Assign each option a power of two, then combine them with OR and interrogate them with AND. This keeps configuration compact in storage and makes checks a single CPU instruction.

READ  = 1  (binary 001)
WRITE = 2  (binary 010)
EXEC  = 4  (binary 100)
set a flag    flags = flags | WRITE
test a flag   if ((flags & WRITE) !== 0) ...
clear a flag  flags = flags & ~WRITE
toggle a flag flags = flags ^ WRITE

Unix file permissions

The familiar chmod 755 is exactly this scheme written in octal. Each octal digit holds three permission bits for one class of user: 7 is 111 (read, write, execute), 5 is 101 (read and execute, no write). Owner, group, and others get one digit each.

Packed colour values

An RGB colour is often stored as a single integer with red in the high byte, green in the middle, and blue in the low byte. Shifting and masking pulls the channels back out.

red   = (rgb >> 16) & 255
green = (rgb >> 8) & 255
blue  = rgb        & 255

Hashing and fast arithmetic

Hash functions lean heavily on XOR and shifts because they mix bits quickly and reversibly. Compilers also turn multiplication and division by powers of two into shifts, since a shift costs a single cycle where a division can cost twenty or more.

Signed vs Unsigned Right Shift

JavaScript has two right shift operators and the difference matters. The arithmetic shift >> preserves the sign bit, copying it into the vacated high positions, so a negative number stays negative. The logical shift >>> always fills with zeros, which turns a negative value into a large positive one. It is also the idiomatic way to coerce a value to an unsigned 32-bit integer, using x >>> 0.

-8 >>  1  = -4          sign preserved
-8 >>> 1  = 2147483644  zero filled

One more limitation worth knowing: JavaScript converts operands to 32-bit integers before applying any bitwise operator, so values above 2 to the power 31 behave unexpectedly and bit operations silently truncate anything larger. For wider values use BigInt, which supports the same operators without the 32-bit ceiling. The calculator above works on 32-bit unsigned values.

Bit level work usually goes hand in hand with base conversion. Browse the full developer tools collection for binary, octal, and hexadecimal converters plus other number utilities.

Frequently asked questions

5 answers
The calculator supports AND, OR, XOR, NAND, NOR, XNOR, NOT, left shift (<<), and right shift (>>). Results are shown simultaneously in decimal, binary, hexadecimal, and octal, so you can use the output in any number base you need.

More JSON Tools

About Bitwise Operations

Bitwise operations work at the binary level, manipulating individual bits within integers. They are fundamental to systems programming, embedded development, cryptography, graphics, and network protocol implementation. AND is used for masking, OR for setting bits, XOR for toggling and simple encryption, and bit shifts for fast multiplication or division by powers of two. This calculator lets you test bitwise expressions instantly and see results in all four common number bases, making it an essential tool for low-level developers and computer science students.