Programmer Calculator
- HEX
- 0
- DEC
- 0
- OCT
- 0
- BIN
- 0
Bits
This programmer calculator works the way integers work inside a computer: on a fixed number of bits, in two's complement, with wrap-around. Type in hexadecimal, decimal, octal or binary and see the value in all four bases at once, combine values with AND, OR and XOR, shift and rotate them, and flip single bits. It is built for firmware, networking, embedded and systems work, and for learning how binary numbers behave.
- HEX, DEC, OCT and BIN shown at the same time
- BYTE, WORD, DWORD and QWORD, signed (two's complement) or unsigned
- AND, OR, XOR, NOT, NAND and NOR
- Left and right shifts, arithmetic and logical, and rotates
- Overflow flag and C operator precedence
- A clickable bit view of all 64 bits
How to use the programmer calculator
- Pick the base you want to type in (HEX, DEC, OCT or BIN), the word size (BYTE, WORD, DWORD or QWORD) and whether numbers are signed. Keys for digits the base does not have are switched off.
- Type an expression with the keys or your keyboard, for example F0 AND 3C, then press =. The LCD shows the result in all four bases; the base you type in is the large line.
- Use Lsh and Rsh to shift, >>> for a logical shift right, RoL and RoR to rotate, and NOT to invert every bit. Brackets and the usual C operator precedence apply.
- Open Bits to see every bit of the value. Click a bit to flip it; bits above the word size are greyed out.
- Press the copy key to copy the value in the current base with its prefix (0x, 0o or 0b). AC clears everything; your base, word size and last value are remembered in this browser.
Hexadecimal, decimal, octal and binary
A base is the number of different digits a position can hold. Binary uses 0 and 1, octal 0 to 7, decimal 0 to 9 and hexadecimal 0 to 9 and A to F. Every position is worth the base times the position to its right, so the same number has a different spelling in each base:
Hexadecimal is popular because each hex digit is exactly four bits, so a byte is always two hex digits and a 64-bit value is 16. Octal groups bits by three, which is why Unix file permissions such as 755 are written in octal.
Signed numbers and two's complement
A computer stores a negative integer in two's complement: invert every bit and add one. With 8 bits, minus one is FF and the range is −128 to 127; unsigned, the same 8 bits mean 0 to 255.
| Word | Bits | Unsigned | Signed (two's complement) |
|---|---|---|---|
| BYTE | 8 | ||
| WORD | 16 | ||
| DWORD | 32 | ||
| QWORD | 64 |
Switching between signed and unsigned does not change any bit, only how the bits are read: 1111 1111 is 255 unsigned and −1 signed. Changing the word size keeps the lowest bits, the way a cast does in C.
Bitwise operators, shifts and rotates
Bitwise operators work on each pair of bits separately. Shifts move all bits left or right; rotates move the bits that fall off one end back in at the other.
| Key | What it does | Example |
|---|---|---|
| AND | 1 only where both bits are 1. Used to mask bits. | |
| OR | 1 where either bit is 1. Used to set bits. | |
| XOR | 1 where the bits differ. Used to toggle bits. | |
| NOT | Inverts every bit of the word. | |
| NAND · NOR | AND or OR followed by NOT. | |
| Lsh | Moves bits left and fills with zeros; each step multiplies by 2 until bits fall off. | |
| Rsh | Moves bits right. On a signed word the sign bit is copied (arithmetic shift), so it divides by 2 rounding down; on an unsigned word zeros come in. | |
| >>> | Logical shift right: zeros always come in, even on a signed word. | |
| RoL · RoR | Rotates the bits within the word; nothing is lost. | |
| mod | Remainder of integer division. As in C, division rounds toward zero and the remainder has the sign of the dividend. |
Operator precedence
Expressions follow the precedence of C, C++, Java and JavaScript: NOT and the minus sign first, then × ÷ mod, then + −, then the shifts and rotates, then AND and NAND, then XOR, then OR and NOR. Operators of the same level are applied left to right.
This surprises people who expect shifts to bind tighter than addition: 1 + 2 Lsh 3 is 24, not 17. Use brackets when in doubt; the calculator shows the expression exactly as it will be evaluated.
Overflow and wrap-around
When an addition, subtraction, multiplication or division gives a result that does not fit the word, the result wraps around modulo two to the power of the word size, exactly as the hardware does, and the LCD shows OVF:
Shifts and bitwise operators never set OVF: discarding bits is what they are for. Typing a number that is too big for the word is refused rather than silently cut.
How exact is it?
Every value is held as an exact integer (JavaScript BigInt), so all 64 bits of a QWORD are exact. Ordinary floating point keeps only 53 bits: it cannot tell 9007199254740992 from 9007199254740993, which this calculator always can.
Accuracy and test cases
Every operator on this page is checked automatically before each release against 56 test cases, including the C rules for division, remainder and shifts, and every word size. The table shows a selection; run all of them in your own browser to see the same engine you are using pass.
| Expression | Exact value | Calculator shows (DEC) | Plain floating point | Check |
|---|---|---|---|---|
| Bases and word sizes u8 is an unsigned BYTE, i64 a signed QWORD, and so on. | ||||
| 255 | — | — | ||
| −1 | — | — | ||
| 18446744073709551615 | — | — | ||
| −9223372036854775808 | — | — | ||
| Overflow and wrap-around The OVF flag is checked too. | ||||
| −128 | — | — | ||
| — | −2147483648 | — | — | |
| Integer division and remainder Rounded toward zero, remainder with the sign of the dividend, as in C. | ||||
| −3 | — | — | ||
| — | −1 | — | — | |
| Integers that floating point cannot hold Above 2⁵³ a double loses the last digits; BigInt keeps them. | ||||
| 9007199254740993 | 9007199254740992 | — | ||
| — | 121932631112635269 | 121932631112635260 | — | |
| Bitwise logic Each bit on its own. | ||||
| 48 | — | — | ||
| 240 | — | — | ||
| 65535 | — | — | ||
| Shifts and rotates Arithmetic and logical shifts, rotate counts larger than the word. | ||||
| — | −128 | — | — | |
| — | −4 | — | — | |
| 60 | — | — | ||
| 3 | — | — | ||
| Operator precedence The same order as C and JavaScript. | ||||
| 24 | — | — | ||
| 10 | — | — | ||
| Invalid input What the calculator says instead of a wrong number. | ||||
| — | Cannot divide by zero | — | — | |
| — | That digit does not exist in this base | — | — | |
| — | Too large for this word size | — | — | |
Show every test case
Related calculators
To convert a single number between bases, or for other kinds of maths, try these calculators.
Frequently asked questions
Why does 127 + 1 give −128?
In a signed BYTE the largest value is 127. Adding 1 needs a ninth bit, which the word does not have, so the result wraps around to −128 and OVF lights up. Choose a larger word size or unsigned to get 128.
What is the difference between Rsh and >>>?
Rsh is an arithmetic shift on a signed word: it copies the sign bit, so −16 Rsh 2 is −4. >>> is a logical shift: it always shifts in zeros, so on a signed BYTE −16 >>> 2 is 60.
Why is FF equal to −1?
Because the word is signed. In two's complement the pattern with every bit set is −1. Untick Signed and the same FF reads 255.
Why does my result differ from another programmer calculator?
Check the word size and signedness first: the same bits mean different numbers in different words. Then check precedence: this calculator follows C, so shifts bind less tightly than + and −.
How does integer division round?
Toward zero, as in C and most processors: −7 ÷ 2 is −3 and −7 mod 2 is −1. The quotient times the divisor plus the remainder always gives back the dividend.
Can I type with the keyboard?
Yes, while the calculator has focus: digits and A to F, + − * / %, & | ~ for AND, OR and NOT, < and > for the shifts, brackets, Enter for =, Backspace and Escape.
Is it exact for 64-bit numbers?
Yes. Values are exact integers, not floating point, so every bit of a QWORD is kept. The test cases below include values above 2⁵³ that ordinary floating point gets wrong.