Calculate bitwise operations on integers: AND, OR, XOR, NOT, NAND, NOR, XNOR, left and right shifts (arithmetic and logical) and rotates. Pick 8, 16, 32 or 64-bit width and see the result in decimal, hex, binary and octal with a bit-by-bit grid.
Last updated:
Decimal, 0x hex, 0b binary or 0o octal; negatives allowed.
Second operand, or the number of bits to shift or rotate.
Enter your values to see the result.
Advertisement
Advertisement
How to use the Bitwise Calculator
Enter A in decimal, hex (0x), binary (0b) or octal (0o).
Pick the operation, e.g. AND, XOR or a shift.
Enter B, or the number of bits to shift or rotate.
Choose the bit width and whether to show the result as signed.
Read the result in every base and check the bit grid.
Bitwise operations at a glance
Operation
Symbol
Rule per bit
Example (8-bit)
AND
A & B
1 if both are 1
1100 1100 & 1010 1010 = 1000 1000 (136)
OR
A | B
1 if either is 1
1100 1100 | 1010 1010 = 1110 1110 (238)
XOR
A ^ B
1 if they differ
1100 1100 ^ 1010 1010 = 0110 0110 (102)
NOT
~A
flip every bit
~1100 1100 = 0011 0011 (51)
NAND / NOR / XNOR
~(A&B), ~(A|B), ~(A^B)
inverse of AND / OR / XOR
NAND = 0111 0111 (119)
Left shift
A << n
move left, fill with 0
0000 0101 << 2 = 0001 0100 (20)
Arithmetic right shift
A >> n
move right, copy sign bit
1111 0000 (−16) >> 2 = 1111 1100 (−4)
Logical right shift
A >>> n
move right, fill with 0
1111 0000 >>> 2 = 0011 1100 (60)
Rotate left / right
ROL / ROR
bits wrap around
1001 0110 ROL 1 = 0010 1101 (45)
Two's complement and bit width
With W bits, unsigned values run from 0 to 2W − 1 and signed (two's complement) values from −2W−1 to 2W−1 − 1. A negative number −x is stored as 2W − x, so −16 in 8 bits is 256 − 16 = 240 = 1111 0000. Useful identities: ~x = −x − 1, x << n = x × 2n (mod 2W), x >> n = ⌊x ÷ 2n⌋ for signed x, and x & (x − 1) clears the lowest set bit.
Common tricks: test bit k with (x >> k) & 1, set it with x | (1 << k), clear it with x & ~(1 << k) and toggle it with x ^ (1 << k).
Frequently asked questions
What does bitwise AND do?
AND compares two numbers bit by bit and returns 1 only where both bits are 1. For example 204 & 170 is 11001100 & 10101010 = 10001000, which is 136. It is often used to mask (keep) selected bits.
What is the difference between >> and >>>?
>> is an arithmetic right shift: it copies the sign bit in from the left, so negative numbers stay negative (−16 >> 2 = −4). >>> is a logical right shift: it fills with zeros, so in 32 bits −16 >>> 2 = 1073741820.
How does bitwise NOT work for negative numbers?
NOT flips every bit. In two's complement, ~x always equals −x − 1, so ~0 = −1 and ~5 = −6. Shown as unsigned, ~0 is the largest value for the width, e.g. 255 for 8 bits or 4294967295 for 32 bits.
Why does the bit width matter?
NOT, shifts, rotates and negative numbers depend on how many bits the value has. ~0 is 255 in 8 bits but 65535 in 16 bits, and 1 << 8 is 0 in 8 bits but 256 in 16 bits. Pick the width your language or hardware uses.
What width do programming languages use?
JavaScript bitwise operators work on 32-bit signed integers (BigInt for larger), Java and C# int is 32-bit and long 64-bit, and C/C++ depend on the type (uint8_t, int32_t, uint64_t…). Python integers have unlimited width, so ~x is still −x − 1.
What is XOR used for?
XOR returns 1 where bits differ. It is used to toggle bits (x ^ mask), compare values, compute parity and checksums, and in simple ciphers, because applying the same XOR twice gives back the original value.
Are all the tools on FreeToolCabin tested for quality and accuracy?
Yes! Every tool on our site undergoes automated Q/A testing in real browser environments to ensure high precision, correct output, and zero errors. If you happen to spot a bug or have a suggestion, please contact us at [email protected] and our team will review it right away.