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.
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:
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.
| A | B | A & B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 0 |
| 1 | 0 | 0 |
| 1 | 1 | 1 |
2. OR (|) Operation
Returns 1 if at least one bit is 1. Used for setting bits and combining flags.
| A | B | A | B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 1 |
3. XOR (^) Operation
Returns 1 if bits are different. Used for toggling bits and simple encryption.
| A | B | A ^ B |
|---|---|---|
| 0 | 0 | 0 |
| 0 | 1 | 1 |
| 1 | 0 | 1 |
| 1 | 1 | 0 |
4. NOT (~) Operation
Inverts every bit (0→1, 1→0) within the selected bit width.
| A | ~A |
|---|---|
| 0 | 1 |
| 1 | 0 |
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.
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
| Operation | Symbol | Description | Example |
|---|---|---|---|
| AND | & | Both bits must be 1 | 1010 & 1100 = 1000 |
| OR | | | At least one bit is 1 | 1010 | 1100 = 1110 |
| XOR | ^ | Bits are different | 1010 ^ 1100 = 0110 |
| NOT | ~ | Inverts all bits (width-dependent) | NOT 00001111 = 11110000 (8-bit) |
| NAND | ⊼ | NOT of AND | 1010 ⊼ 1100 = 0111 |
| NOR | ⊽ | NOT of OR | 1010 ⊽ 1100 = 0001 |
| XNOR | ⊙ | NOT of XOR (equality) | 1010 ⊙ 1100 = 1001 |
| Left shift | << | Shift left, fill with 0 | 00001111 << 1 = 00011110 |
| Right shift | >> | Logical shift right, fill with 0 | 11110000 >> 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.
Related Tools
You might also find these tools useful
Binary Converter
Convert text, UTF-8 bytes, and binary values without focusing only on readable messages.
Binary Calculator
Add, subtract, multiply, and divide binary numbers for math and computer science exercises.
Binary to Decimal
Turn base-2 numbers into decimal values for programming, networking, and study notes.
Binary to HEX
Compress long binary strings into hexadecimal groups for code, memory, and color checks.
Decimal to Binary
Convert everyday base-10 numbers into binary with clear fixed-width output.
Decimal to HEX
Translate decimal values into compact hexadecimal notation for technical references.