Bitwise Calculator
CV-27Type an expression such as 12 AND 10 and see the result in decimal, hex and binary at 8, 16, 32 or 64 bits. It supports AND, OR, XOR, NAND, NOR, XNOR, NOT and shifts.
Runs in your browser. Nothing is uploaded.
Expressions (one per line, such as 12 AND 10 or NOT 5)
Results
How to use it
- Type one expression per line, such as 12 AND 10, 12 | 10, 1 << 4 or NOT 5.
- Choose a bit width of 8, 16, 32 or 64. Numbers can be decimal, 0x hex, 0b binary or 0o octal.
- Choose logical or arithmetic for right shifts if you use >>.
- Click Calculate and read the unsigned and signed decimal, hex and binary results.
- Copy the result or download it as a text file.
How the width works
Every value is treated as a whole number of the width you pick. A negative decimal is stored as the matching unsigned value, so -1 is 255 at 8 bits and 65535 at 16 bits. A number that does not fit, such as 300 at 8 bits, gives an error and is not cut off. Each result is shown as unsigned decimal, signed decimal, hex padded to the width and binary in groups of 4 digits. Values use BigInt, so 64-bit results are exact.
The operations
AND keeps a bit when both inputs have it, OR when either has it, and XOR when exactly one has it. NAND, NOR and XNOR are those results flipped. NOT flips every bit within the width, so NOT 5 at 8 bits is 250. Shifts move bits left or right. A left shift drops bits that move past the top. A right shift fills with 0 (logical) or copies the sign bit (arithmetic), and the amount must be from 0 to the width.
What it does not do
Each line holds one operator. There are no brackets, no chained expressions such as 1 AND 2 OR 3, and no rotates, additions or other arithmetic. The symbols & | ^ ~ work in place of AND, OR, XOR and NOT. Both operands must fit the chosen width, so use a wider width for larger values.
Error messages and what to do
| Message | What it means | Fix |
|---|---|---|
300 does not fit in 8 bits (allowed -128 to 255). | A value is outside what the chosen width can hold. | Choose a larger bit width or use a smaller number. |
Could not read "12 PLUS 10". Write it like 12 AND 10, 12 & 10, 1 << 4 or NOT 5. | The line is not in a form the page understands. | Use one of AND, OR, XOR, NAND, NOR, XNOR, << or >>, or start with NOT. |
The shift amount must be from 0 to 32. | A shift amount is larger than the bit width, or negative. The number in the message is the current width. | Use a shift from 0 up to the width, or choose a wider width. |
Questions people ask
What is 12 AND 10?
8. In binary 12 is 1100 and 10 is 1010, and AND keeps only the bits set in both, which gives 1000. OR gives 14 and XOR gives 6 for the same pair.
What does NOT 5 give?
It depends on the width. At 8 bits, NOT 5 is 250, because every bit is flipped. At 32 bits it is 4294967290, which is -6 when read as a signed number. The page shows both readings.
What is the difference between logical and arithmetic right shift?
A logical right shift fills the empty bits on the left with 0. An arithmetic shift copies the top bit, the sign bit, so negative numbers stay negative. For positive numbers they give the same answer.
Why does a negative number show up as a big number?
The unsigned line shows the same bits read as a positive number. At 8 bits, -1 is 11111111, which is 255 unsigned. The signed line reads the top bit as a sign and shows -1.
Can it handle 64-bit values exactly?
Yes. It uses BigInt, so values up to 18446744073709551615 are exact at 64 bits. Ordinary JavaScript numbers lose exactness above 9007199254740991, which is why this page does not use them for the arithmetic.
What is the difference between NAND, NOR and XNOR?
They are AND, OR and XOR with the result flipped. NAND is 0 only when both bits are 1, NOR is 1 only when both bits are 0, and XNOR is 1 when the two bits are equal.
About this tool
Works on whole numbers of a fixed width (8, 16, 32 or 64 bits) using BigInt, so 64-bit values are exact. Each line is one operation: AND, OR, XOR, NAND, NOR, XNOR, a shift (<< or >>) or NOT. The symbols &, |, ^ and ~ also work. Numbers can be decimal, 0x hex, 0b binary or 0o octal, and a negative decimal is stored as the matching unsigned value of that width (-1 in 8 bits is 255). A value that does not fit the width is an error, not truncated. Left shifts drop bits shifted past the top. Results are shown as unsigned decimal, signed decimal, hex and binary. Only one operator per line; there are no brackets or chained expressions.