How to use the bitwise calculator
- Choose the operation: AND, OR, XOR, NOT, or a left or right shift.
- Choose the bit width (8, 16, 32 or 64) and whether numbers are signed or unsigned.
- Enter number A and, for AND, OR and XOR, number B. For a shift, enter the shift amount. Use decimal, 0x for hex or 0b for binary.
- Read the result in decimal, binary and hex, with the working shown step by step.
Formula
AND: each bit is 1 only if both bits are 1
OR: each bit is 1 if either bit is 1. XOR: 1 if exactly one bit is 1
NOT: every bit is flipped. A shifted left by n is A x 2^n with bits above the width dropped
All numbers are held in the chosen number of bits. A signed number uses two's complement, so the top bit means negative. A right shift of a signed number copies the sign bit, and the zero fill shift fills with 0.
12 and 10
In binary 12 is 1100 and 10 is 1010. 12 AND 10 keeps only the bit that is 1 in both, which is 1000, or 8. 12 OR 10 is 1110, or 14, and 12 XOR 10 is 0110, or 6.
NOT 12 at 8 bits flips 00001100 to 11110011, which is 243 as an unsigned number. At 32 bits signed, the same NOT gives -13.
Width, sign and overflow
Every number must fit the width you choose. An unsigned 8 bit number runs from 0 to 255 and a signed 8 bit number from -128 to 127. A number outside that range is rejected with its valid range, and nothing is silently wrapped. Negative numbers in signed mode are stored in two's complement, which you can inspect with the twos complement converter.
Shifting left can push 1 bits past the top of the width. Those bits are dropped, the result wraps within the width, and a warning tells you bits were lost. A shift amount must be from 0 to the width minus one, because shifting by the full width or more is undefined in many languages. 255 shifted left by 1 at 8 bits unsigned is 254, with the top bit lost.
Using the result
Binary output is grouped in fours so it is easy to read, and the hex output is padded to the width. The line labeled Same bits read as shows what the pattern means with the other sign setting. Be careful when comparing with code: some languages use 32 bit signed integers for bit operations and treat larger numbers differently. Pick the width your own language uses. See also the number base converter, the binary translator and the IP address converter.
Assumptions and limits
- Numbers are whole numbers that fit the chosen width and sign setting.
- Signed numbers use two's complement.
- Shift amounts must be from 0 to width minus 1.
- Results show exactly what the operation does at the chosen width. Your language may differ.
Frequently asked questions
What is 12 AND 10?
It is 8. In binary 1100 AND 1010 is 1000, because only the third bit from the right is set in both numbers.
What is the difference between a signed and a logical right shift?
A signed right shift copies the sign bit into the empty top positions, so negative numbers stay negative. A zero fill shift always puts 0 there.
Why is my number rejected?
It does not fit the width. An 8 bit unsigned number is 0 to 255, and signed is -128 to 127. Choose a larger width or a smaller number.
How do I write hex or binary input?
Start hex with 0x, such as 0xFF, and binary with 0b, such as 0b1010. Plain digits are decimal.