Bitwise Calculator
Compute AND, OR, XOR, NOT, and shift operations on integers. See all results simultaneously in decimal, hex, and binary with a visual bit grid. 8, 16, 32, and 64-bit modes.
Operand A
182 · 0xB6 · 5 set bits
Operand B
202 · 0xCA · 4 set bits
Bit Visualization
A
5 set bits
B
4 set bits
A AND B
2 set bits
A OR B
7 set bits
A XOR B
5 set bits
All Operations
| Operation | Decimal | Hex | Binary | Bits |
|---|---|---|---|---|
| A | 182 | 0xB6 | 1011 0110 | 5 |
| B | 202 | 0xCA | 1100 1010 | 4 |
| A AND B | 130 | 0x82 | 1000 0010 | 2 |
| A OR B | 254 | 0xFE | 1111 1110 | 7 |
| A XOR B | 124 | 0x7C | 0111 1100 | 5 |
| NOT A | 73 | 0x49 | 0100 1001 | 3 |
| NOT B | 53 | 0x35 | 0011 0101 | 4 |
| A << 1 | 108 | 0x6C | 0110 1100 | 4 |
| A >> 1 | 91 | 0x5B | 0101 1011 | 5 |
| A >>> 1 (arith) | 219 | 0xDB | 1101 1011 | 6 |
Bitwise Operation Truth Tables
Each bitwise operation is applied to corresponding bit pairs independently. Here is the truth table for all operations on individual bits A and B:
| A | B | AND | OR | XOR | NOT A | NOT B |
|---|---|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 | 1 | 1 |
| 0 | 1 | 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 1 | 1 | 0 | 1 |
| 1 | 1 | 1 | 1 | 0 | 0 | 0 |
Common Bit Manipulation Patterns
These are the three most common bit manipulation operations in systems and embedded programming:
Set bit n
x |= (1 << n)OR with a mask that has only bit n set. Forces bit n to 1 regardless of its current value.
Clear bit n
x &= ~(1 << n)AND with the bitwise NOT of the mask. Forces bit n to 0 regardless of its current value.
Toggle bit n
x ^= (1 << n)XOR with the mask. Flips bit n — 0 becomes 1, 1 becomes 0.
Shift Operations and Arithmetic
Shift operations move all bits left or right by a specified number of positions. Left shifting by n is equivalent to multiplying by 2ⁿ (for values that do not overflow). Right shifting by n is equivalent to integer division by 2ⁿ. This makes shifts faster than multiplication/division on most hardware and is why compilers emit shift instructions for power-of-two factors. For example: 100 << 2 = 400, and 400 >> 2 = 100. In networking, shift operations extract nibbles, bytes, and fields from packed integer representations of IP addresses and protocol headers.
Frequently Asked Questions
What is a bitwise operation?
A bitwise operation works directly on the individual bits of an integer rather than its numeric value. Each bit in the operands is processed independently according to the operation's truth table. The six fundamental operations are AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). They are extremely fast — a single CPU instruction — and are used extensively in low-level programming, embedded systems, networking, cryptography, and graphics.
What is the difference between AND, OR, and XOR?
AND (&) outputs 1 only when both input bits are 1 — used to mask or clear specific bits. OR (|) outputs 1 when at least one input bit is 1 — used to set specific bits. XOR (^) outputs 1 when the bits differ — used to toggle bits, detect changes, or implement XOR-based encryption. NOT (~) inverts every bit. A common pattern: to set bit n, OR with (1 << n). To clear bit n, AND with ~(1 << n). To toggle bit n, XOR with (1 << n).
What is the difference between logical and arithmetic right shift?
A logical right shift (>>>) fills vacated bits on the left with 0, regardless of sign. An arithmetic right shift (>>) fills vacated bits with the sign bit (0 for positive numbers, 1 for negative/two's complement numbers) — this preserves the sign and is equivalent to dividing by 2 for signed integers. In most C-family languages, >> on unsigned integers is logical; on signed integers it is implementation-defined (usually arithmetic). JavaScript uses >>> for logical and >> for arithmetic.
Why do results differ between 8-bit, 16-bit, and 32-bit modes?
The bit size determines the mask applied to the result. An 8-bit NOT of 0 gives 0xFF (255 decimal), because ~0 = 0xFFFFFFFF in 32-bit arithmetic, masked to 8 bits gives 0xFF. A 16-bit NOT of 0 gives 0xFFFF (65535). Left shifts also differ — 1 << 7 in 8-bit mode is 128, but the same value left-shifted once more would overflow and become 0. This tool masks all results to the selected bit width so you always see the value as the hardware would.
What are common uses of bit manipulation in real software?
Bit manipulation appears throughout systems programming: flag fields (storing multiple boolean options in one integer), network masks (CIDR subnet calculations), permissions (Unix chmod uses 3-bit octal groups), hash functions (rotate left/right in MD5/SHA), packing data for protocols (extracting specific byte ranges), fast arithmetic (shifting left by n is multiply by 2^n, right shift is integer divide), and GPU programming (swizzle operations on pixel channels). Embedded firmware uses bit operations to toggle hardware pins and read register flags.