Perform bitwise operations (AND, OR, XOR, NOT) and bit shift operations on integers with interactive visual bit diagrams showing each bit position.
Bitwise Calculator
Perform AND, OR, XOR, bit shift, and NOT operations on binary, decimal, hexadecimal, or octal numbers
Try These Examples:
Bitwise operations work directly on the individual bits inside a number instead of treating that number as a single value to add or multiply. They sit underneath a surprising share of everyday software, from permission flags and configuration settings to graphics processing, networking and cryptography.
This calculator runs AND, OR, XOR, NOT, left shift and right shift on your input and shows the binary breakdown behind the result, so the answer is never just a number, it’s a visible bit-by-bit explanation.
What Each Bitwise Operation Does
AND (&) compares two numbers bit by bit and keeps a 1 only where both inputs have a 1.
OR (|) keeps a 1 wherever either input has a 1.
XOR (^) keeps a 1 only where the two input bits are different from each other.
NOT (~) flips every bit in a single number, turning every 1 into a 0 and every 0 into a 1.
Left shift (<<) moves every bit to a higher position, filling the gap with zeros, which multiplies the number by a power of two.
Right shift (>>) moves every bit to a lower position, which divides the number by a power of two, dropping any remainder.
| A | B | A AND B | A OR B |
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 1 |
How the Bitwise Calculator Works
Enter a number in decimal, binary or hexadecimal, choose a second number if the operation needs one, then pick the operator. The calculator lines both numbers up bit by bit at whatever width you’re working in, usually 8, 16 or 32 bits, applies the operation to each column independently, then converts the result back into the display format you selected.
Step by Step Usage
- Enter the first number.
- Choose its format: decimal, binary or hexadecimal.
- Enter a second number if you’re using AND, OR, XOR or a shift amount. NOT and single-value shifts only need one input.
- Select the operator.
- Calculate, then review the bit-by-bit result alongside the final value.
Worked Examples
AND: 12 & 10
12 in binary is 1100. 10 in binary is 1010.
Comparing column by column: 1&1=1, 1&0=0, 0&1=0, 0&0=0, giving 1000.
Result: 8.
OR: 12 | 10
Same two binary values, 1100 and 1010, compared with OR instead: 1|1=1, 1|0=1, 0|1=1, 0|0=0, giving 1110.
Result: 14.
XOR: 12 ^ 10
1100 XOR 1010: matching bits become 0, differing bits become 1, giving 0110.
Result: 6.
NOT: ~12 (8-bit width)
12 as an 8-bit binary value is 00001100. NOT flips every bit, giving 11110011.
Read as an unsigned 8-bit number, that’s 243. Read as a signed 8-bit two’s complement number, the leading 1 marks it negative, and the value works out to −13. Which interpretation is correct depends entirely on whether the surrounding program treats the value as signed or unsigned, which is worth confirming before trusting the result.
Left Shift: 3 << 2
3 in binary is 011. Shifting left by two positions gives 1100, adding two zero bits on the right.
Result: 12, the same as multiplying 3 by 2 squared, or 4.
Right Shift: 20 >> 2
20 in binary is 10100. Shifting right by two positions drops the two rightmost bits, giving 00101.
Result: 5, the same as dividing 20 by 4 and discarding any remainder.
Real Uses of Bitwise Operations
- Permission flags and bitmasks: individual settings are packed into single bits, combined with OR to turn several on at once, and checked with AND to test whether one specific flag is set.
- Toggling configuration options with XOR, which flips a bit on if it was off and off if it was on, without needing to know its current state in advance.
- Fast multiplication and division by powers of two using shifts, which is noticeably cheaper than general multiplication on many processors and still shows up in performance-sensitive and embedded code.
- Extracting individual color channels from a packed 32-bit RGBA value in graphics work, using a combination of AND to isolate a channel and a shift to move it into position.
- Checksum and simple hashing algorithms, which lean heavily on XOR and shifts to mix input bits together.
- Subnet mask calculations in networking, where AND between an IP address and a mask isolates the network portion of the address.
Common Mistakes with Bitwise Operations
- Mixing up bitwise AND (&) with logical AND (&&) in a programming language. They look similar but behave very differently, and swapping one for the other can silently produce the wrong result instead of throwing an error.
- Forgetting that NOT and right shift behave differently on signed numbers because of two’s complement representation, which can make a result look wrong when it’s actually correct for that particular bit width and sign.
- Assuming arithmetic right shift and logical right shift are interchangeable. They are not, once negative numbers are involved, since arithmetic shift preserves the sign bit and logical shift does not.
- Losing count of bit positions during a shift, which is an easy off-by-one mistake, especially when shifting by a variable amount.
Tips for Getting Accurate Results
- Write out the full binary form of each number before applying an operation by hand rather than trying to reason about it in decimal.
- Decide upfront whether you’re working in a signed or unsigned context, since that changes how NOT and right shift results should be read.
- Keep the bit width consistent, usually 8, 16 or 32 bits, throughout a single calculation to avoid mismatched results.
Bitwise Operators at a Glance
| Operator | Symbol | Description | Example |
| AND | & | 1 only where both bits are 1 | 12 & 10 = 8 |
| OR | | | 1 where either bit is 1 | 12 | 10 = 14 |
| XOR | ^ | 1 only where bits differ | 12 ^ 10 = 6 |
| NOT | ~ | Flips every bit | ~12 (8-bit) = 243 unsigned |
| Left Shift | << | Shifts bits left, multiplies by a power of two | 3 << 2 = 12 |
| Right Shift | >> | Shifts bits right, divides by a power of two | 20 >> 2 = 5 |
Frequently Asked Questions
What is the difference between logical and bitwise operators?
Logical operators like && and || work on whole true or false values and are used for decisions in code. Bitwise operators like & and | work on the individual bits inside a number and are used for manipulating raw data, flags and binary values.
How does XOR toggle bits?
XOR outputs 1 only when two bits differ. If you XOR a bit with 1, a 0 becomes 1 and a 1 becomes 0, which is exactly what toggling means. XORing with 0 always leaves the original bit unchanged.
What does NOT do to a number in two’s complement?
It flips every bit, which on its own gives you what’s called the one’s complement. Adding 1 to that result produces the two’s complement, which is how most systems represent negative numbers internally.
Why do left shifts multiply and right shifts divide?
Shifting bits left is mathematically the same as multiplying by 2 for every position shifted, because each bit position represents a power of two. Shifting right undoes that, dividing by 2 per position and dropping any remainder in the process.
Can bitwise operations be used on decimal or floating point numbers directly?
Not in any meaningful way. Bitwise operations act on the raw bit pattern of a value, and floating point numbers store their bits in a completely different layout (sign, exponent and mantissa) than integers do, so applying AND, OR or XOR directly to a float’s bit pattern doesn’t produce a meaningful numeric result.
Final Words
Bitwise operations look intimidating mostly because they skip straight past decimal intuition and work on raw bits instead. Once you can walk through AND, OR, XOR, NOT, and both shifts by hand, a lot of code that once looked cryptic- permission checks, flag toggles, fast math tricks- starts making direct sense. Use the calculator above to check your own bit-level work, and come back to the worked examples whenever a specific operation needs a refresher.