How to use the Bitwise Operations Calculator
- 1. Enter A and BDecimal, 0b binary or 0x hex. Negative numbers are fine.
- 2. Pick a width8, 16 or 32 bits, and how far to shift A.
- 3. CompareAll results in one table, bit by bit.
The operators
- AND (&): 1 only where both bits are 1. Used to test or clear bits with a mask.
- OR (|): 1 where either bit is 1. Used to set flags.
- XOR (^): 1 where the bits differ. Used to toggle bits and in tricks like finding the one unpaired number.
- NOT (~): flips every bit. In two's complement, ~x = −x − 1.
- Left shift (<<): moves bits left, multiplying by 2 per place.
- Arithmetic right shift (>>): moves bits right and copies the sign bit, so −8 >> 1 is −4.
- Logical right shift (>>>): moves bits right and fills with 0s, as in Java and JavaScript.
Each result is shown as the bit pattern, its signed and unsigned values, and hex, wrapped to the width you chose, the way a C or Java integer of that size would store it.
Worked example
With A = 12 (0000 1100) and B = 10 (0000 1010) in 8 bits:
- 12 & 10 = 8 (0000 1000)
- 12 | 10 = 14 (0000 1110)
- 12 ^ 10 = 6 (0000 0110)
- ~12 = −13 signed, 243 unsigned (1111 0011)
- 12 << 2 = 48 and 12 >> 2 = 3
Common interview uses: n & 1 tells odd from even; n & (n − 1) is 0 exactly when n is a power of 2; and x ^ x = 0 lets you find the unique element in a list where every other number appears twice. Try a negative A, like −8, to see how >> and >>> differ.
Frequently asked questions
Why is ~12 equal to −13?
Flipping all bits of 12 gives the two's complement pattern for −13. In general ~x = −x − 1.
Does JavaScript have 64-bit bitwise operators?
Normal numbers use 32-bit operations. BigInt supports &, |, ^, ~ and shifts on any size.
What happens if a value doesn't fit the width?
The tool asks you to pick a bigger width rather than silently wrapping your input.
Is the bitwise operations calculator free to use?
Yes, the bitwise operations calculator is free and costs nothing. Your first calculation shows a short form for your name and WhatsApp number one time; once that's done, this tool and every other Uncodemy tool open with no form.