Bitwise Operations Calculator

Compute AND, OR, XOR, NOT, NAND, NOR, XNOR, and left/right shifts on unsigned binary values. Choose an 8, 16, 32, or 64-bit width — results are computed with exact integer math, not JavaScript's 32-bit number operators.

Bit width

Values are treated as unsigned bit patterns. For signed (two's complement) interpretation, use the Two's Complement Calculator.

What Are Bitwise Operations?

Bitwise operations act directly on the individual bits of a binary value rather than on its numeric magnitude. This tool supports the standard logic operations — AND (&), OR (|), XOR (^), NOT (~), NAND, NOR, and XNOR — plus left and right bit shifts.

All values here are unsigned bit patterns evaluated at a fixed width you choose (8, 16, 32, or 64 bits). For arithmetic on binary numbers, use the Binary Calculator. For signed two's complement values, use the Two's Complement Calculator.

Why Bit Width Matters

AND, OR, and XOR give the same result regardless of width once operands are zero-padded to the same length. NOT and shifts are different — their result depends entirely on how many bits you're operating over:

NOT 00001111 at 8-bit = 11110000
NOT 00001111 at 16-bit = 1111111111110000

This calculator computes with exact integer math (BigInt) instead of JavaScript's native bitwise operators, which silently coerce numbers to 32-bit signed integers and produce incorrect results above that range. That makes the 64-bit width exact, not an approximation.

Bitwise Operations Explained

Truth tables and examples for each operation:

1. AND (&) Operation

Returns 1 only if both bits are 1. Used for masking bits and checking flags.

Truth Table:
ABA & B
000
010
100
111
Example:
1010 (10)
& 1100 (12)
1000 (8)

2. OR (|) Operation

Returns 1 if at least one bit is 1. Used for setting bits and combining flags.

Truth Table:
ABA | B
000
011
101
111
Example:
1010 (10)
| 1100 (12)
1110 (14)

3. XOR (^) Operation

Returns 1 if bits are different. Used for toggling bits and simple encryption.

Truth Table:
ABA ^ B
000
011
101
110
Example:
1010 (10)
^ 1100 (12)
0110 (6)

4. NOT (~) Operation

Inverts every bit (0→1, 1→0) within the selected bit width.

Truth Table:
A~A
01
10
Example (8-bit):
~ 00001111
11110000

5. Left Shift (<<) and Right Shift (>>)

A left shift moves bits toward the high end, discarding bits that fall outside the selected width and filling with 0 on the low end. The right shift here is a logical (unsigned) shift: it moves bits toward the low end and fills with 0 on the high end — it does not sign-extend.

Left shift example (8-bit):
00001111
<< 1
00011110
Right shift example (8-bit):
11110000
>> 1
01111000

Common Uses of Bitwise Operations

Flags & Permissions

AND to check a flag, OR to set one, XOR to toggle one — the basis of file permission bits and feature flags.

Cryptography

XOR is the core operation in stream ciphers and one-time pads because it's its own inverse.

Network Subnet Masks

AND-ing an IP address with a subnet mask isolates the network portion of the address.

Fast Powers of Two

Left shift by n multiplies by 2ⁿ; logical right shift by n divides by 2ⁿ, discarding the remainder.

Bitwise Operations Cheat Sheet

OperationSymbolDescriptionExample
AND&Both bits must be 11010 & 1100 = 1000
OR|At least one bit is 11010 | 1100 = 1110
XOR^Bits are different1010 ^ 1100 = 0110
NOT~Inverts all bits (width-dependent)NOT 00001111 = 11110000 (8-bit)
NANDNOT of AND1010 ⊼ 1100 = 0111
NORNOT of OR1010 ⊽ 1100 = 0001
XNORNOT of XOR (equality)1010 ⊙ 1100 = 1001
Left shift<<Shift left, fill with 000001111 << 1 = 00011110
Right shift>>Logical shift right, fill with 011110000 >> 1 = 01111000

Frequently Asked Questions

What is the difference between AND and OR?

AND returns 1 only if both bits are 1. OR returns 1 if at least one bit is 1. Example: 1010 & 1100 = 1000, but 1010 | 1100 = 1110.

When should I use XOR?

XOR is useful for toggling bits, comparing bit patterns for equality (via XNOR), and simple stream-cipher-style encryption. A ^ B ^ B always equals A.

Why does NOT depend on the bit width?

NOT flips every bit in the selected width, including leading zeros. NOT 00001111 is 11110000 at 8-bit but 1111111111110000 at 16-bit — the same value, different width, different result.

Is the right shift here signed or unsigned?

Unsigned (logical). It always fills with 0 from the left, regardless of the leading bit. For sign-aware arithmetic shifting, interpret the pattern with the Two's Complement Calculator first.

What is NAND and why is it significant?

NAND is NOT of AND. It's a universal gate — every other logic gate (AND, OR, NOT, XOR) can be built from NAND gates alone, which is why it's common in digital circuit design.

Can I use this on hexadecimal input?

Convert hex to binary first (with the Hex to Binary tool), then run the operation here. Example: 0xF & 0xC = 0x8, since 1111 & 1100 = 1000.