Find your next tool

Browse tools or search by task

Explore JSONToonPro

Number Converter Tools

Bitwise Calculator – AND, OR, XOR & Bit Shifts

Calculate bitwise AND, OR, XOR, NAND, NOR, XNOR, NOT and shifts online. View results in binary, decimal and hex instantly.

Runs locally in your browser. Nothing you paste is uploaded.

Bitwise Calculator workspace

Operation

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

How to Use the Bitwise Calculator

Enter integer operands and select an operation. Compare binary, decimal and hexadecimal representations to see which bits changed. Confirm the bit width and signed behavior before transferring a result to another language.

AND, OR and XOR Explained

AND sets a bit only when both inputs have it; OR sets it when either does; XOR sets it when the inputs differ. These operations are useful for masks, flags and toggling selected bits.

NOT, NAND, NOR and XNOR

NOT flips bits within the implementation’s integer width. NAND, NOR and XNOR invert AND, OR and XOR results. This calculator displays the resulting bit pattern as an unsigned 32-bit value.

Left and Right Bit Shifts

A left shift moves bits toward higher positions, while a right shift moves them lower. Signed and unsigned right shifts handle the high bit differently. Overflow and shift-count behavior depend on the runtime.

Bitwise Examples in Binary and Hex

For 0101 and 0011, AND produces 0001, OR 0111 and XOR 0110. Work in binary when debugging a mask, then copy the decimal or hex representation required by your code.

More examples and technical details

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

What are bitwise operations?

They operate on individual bits of integer representations.

How does XOR work?

XOR produces 1 where corresponding input bits differ and 0 where they match.

What is a left or right bit shift?

A shift moves bit positions left or right; signedness and width determine overflow and high-bit behavior.

How are negative integers handled?

Inputs are converted to 32-bit values, and this calculator displays unsigned results. Its right shift is zero-filling.

Does the calculator run locally?

Yes. Calculations are performed locally.