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.
| A | B | A AND B | A OR B | A XOR B |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 | 1 |
| 1 | 0 | 0 | 1 | 1 |
| 1 | 1 | 1 | 1 | 0 |
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.
| A | B | A NAND B | A NOR B | A XNOR B |
|---|---|---|---|---|
| 0 | 0 | 1 | 1 | 1 |
| 0 | 1 | 1 | 0 | 0 |
| 1 | 0 | 1 | 0 | 0 |
| 1 | 1 | 0 | 0 | 1 |
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.
| A | NOT A |
|---|---|
| 0 | 1 |
| 1 | 0 |
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.
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):
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.
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.
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.
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.