Bitwise Calculator
Calculate AND, OR, XOR, NOT and bit shifts on 8, 16, 32 or 64-bit numbers, with every bit shown side by side.
Runs in your browser. Nothing is uploaded.
Decimal, or with a 0b, 0o or 0x prefix. Negative numbers are stored in two's complement.
How to use the Bitwise Calculator
- Enter A and B in decimal, or as binary (
0b), octal (0o) or hex (0x). Underscores are allowed. - Choose an Operation and a Width of 8, 16, 32 or 64 bits.
- Read the result as aligned bit rows, then as unsigned and signed decimal and as hex.
- For shifts, B is the number of places to shift. NOT uses only A.
Working with individual bits
Bitwise operators act on each bit of a number separately. They’re used to pack several true/false flags into one integer, test and set bits in hardware registers, compute subnet masks, write fast arithmetic, build hash functions, and work with file permissions and network protocols. The logic is simple, but doing it in your head with 32 or 64 bits is not, so this calculator lays the operands and result out bit by bit.
The operations
- AND (&) gives 1 only where both bits are 1. Use it to test or extract bits with a mask:
0b1100_1010 & 0x0Fkeeps the low four bits and gives0000 1010, which is 10. - OR (|) gives 1 where either bit is 1. Use it to switch flags on.
- XOR (^) gives 1 where the bits differ. Use it to toggle bits, compare values, or in checksums and simple ciphers.
- NOT (~) flips every bit within the chosen width.
- NAND and NOR are NOT applied to AND and OR, the building blocks of digital logic circuits.
- Shift left (<<) moves bits towards the high end, multiplying by 2 for each place until bits fall off the top.
- Logical shift right (>>>) moves bits down and fills with zeros.
- Arithmetic shift right (>>) moves bits down and copies the sign bit, which divides signed numbers by 2 and rounds towards minus infinity.
Width matters
Real integers have a fixed size, and the same operation gives different results in 8, 16, 32 or 64 bits. NOT 0 is 255 as an unsigned byte but 4,294,967,295 as an unsigned 32-bit integer. The calculator wraps every input and result to the width you choose, using two’s complement for negative numbers, and shows both the unsigned and signed interpretation of the result. That makes it easy to match what C, Java, Rust or Go will produce for a given type.
Reading the result
The grid shows A, the operator and B, then a line and the result, with bits grouped in fours so they line up with hex digits. Below it you’ll find the result in unsigned and signed decimal, hex with leading zeros for the full width, and the number of bits set to 1 (the population count), which is useful when counting flags.
Everything runs locally in your browser.
Frequently asked questions
What is the difference between >> and >>>?
Both shift bits to the right. The logical shift (>>>) fills the left with zeros. The arithmetic shift (>>) copies the sign bit, so negative numbers stay negative. In JavaScript, >> is arithmetic and >>> is logical.
Why does NOT 5 give -6?
NOT flips every bit. In two's complement, flipping all the bits of x gives -x - 1. As an unsigned 8-bit value the same result is 250.
What happens when a result overflows the width?
Bits that move past the chosen width are dropped, exactly as in fixed-size integer types. Shifting 1 left by 8 in an 8-bit width gives 0.
How are negative inputs stored?
As two's complement within the chosen width. -1 in 8 bits is 1111 1111.
Is my input sent anywhere?
No. All calculations use BigInt in your browser.
Tutorials
How to test and set flags with a bitmask
Use AND to read flags, OR to set them and XOR to toggle them, and check each step bit by bit with the bitwise calculator.