Programmer Calculator
Type a number and see it in hex, decimal, octal and binary at once. Pick a word size from 8 to 64 bits, do the arithmetic or the bit work, and watch for the carry and overflow flags.
https://flxcode.com/programmer-calculator/
- T
- 0
- Z
- 0
- Y
- 0
Type with the keyboard or the keys below, or paste a number. Click a row to type in that base.
Bits (click one to flip it)
Try an example
History (this visit only)
Nothing yet. Results appear here, newest first.
Keyboard shortcuts
| 0–9, A–F | type digits (digits outside the input base are refused) |
|---|---|
| + − * / % | add, subtract, multiply, divide, modulo |
| & | ^ ~ | AND, OR, XOR, NOT |
| q w | NAND, NOR |
| < > s | shift left, shift right (logical), shift right (arithmetic) |
| r Shift+R | rotate left, rotate right |
| n | change sign |
| Enter or = | equals (ENTER in RPN mode) |
| Backspace | delete the last digit |
| Esc | clear the number; press again to clear everything |
| x k Delete | RPN: swap X and Y, roll the stack down, drop X |
No ads. No account. Nothing you type or record is uploaded. We count page events with a daily code. Check it.
Problem or idea? Email us
Quick start
- Choose a word size and whether the bits are signed or unsigned.
- Click a row (HEX, DEC, OCT or BIN) to say which base you will type in. Keys that are not digits in that base switch off.
- Type digits, press an operation, type the second number and press =. Or turn on RPN.
- Flip single bits in the bit grid, or copy any row with its prefix.
Worked examples
| Sum | Word | Result in hex | Result in decimal | Flag | What happens |
|---|---|---|---|---|---|
| 0xFF + 0x01 | 8-bit unsigned | 00 | 0 | carry | The byte is full, so it wraps to zero and the carry flag is set. |
| 0x7FFF + 1 | 16-bit signed | 8000 | -32768 | overflow | The largest signed 16-bit value plus one: overflow, and the number turns negative. |
| 0x00 − 0x01 | 8-bit unsigned | FF | 255 | carry | Borrow: zero minus one wraps to the top of the range. |
| -128 SAR 1 | 8-bit signed | C0 | -64 | none | Arithmetic shift keeps the sign bit, so a negative stays negative. |
| 0x80 SHR 1 | 8-bit unsigned | 40 | 64 | none | Logical shift brings in a zero: 0x80 becomes 0x40. |
| 0x81 ROL 1 | 8-bit unsigned | 03 | 3 | carry | The top bit comes round to bit 0, and nothing is lost. |
| NOT 0x0F | 8-bit unsigned | F0 | 240 | none | Every bit flips. At 8 bits NOT x is 0xFF xor x. |
| 17 ÷ 5 | 32-bit unsigned | 00000003 | 3, remainder 2 | none | Integer division: the quotient, and the remainder next to it. |
| -17 ÷ 5 | 32-bit signed | FFFFFFFD | -3, remainder -2 | none | Division rounds toward zero, so the remainder keeps the sign of -17. |
| -7 MOD 3 | 8-bit signed | FF | -1 | none | MOD takes the sign of the first number, as in C. |
Word sizes and ranges
| Bits | Signed minimum | Signed maximum | Unsigned maximum | In hex |
|---|---|---|---|---|
| 8 (byte) | -128 | 127 | 255 | 0xFF |
| 16 (word) | -32768 | 32767 | 65535 | 0xFFFF |
| 32 (long) | -2147483648 | 2147483647 | 4294967295 | 0xFFFFFFFF |
| 64 (quad) | -9223372036854775808 | 9223372036854775807 | 18446744073709551615 | 0xFFFFFFFFFFFFFFFF |
The names byte, word, long and quad follow the 68000 and Amiga convention. Other families use different names: on x86 a word is 16 bits, and a double word is 32.
Two's complement: why 0xFF is -1
A computer stores a negative number by counting backwards from zero in a fixed number of bits. One less than 0 wraps to all ones. So -1 is all ones in every word size, -2 is all ones except the last bit, and so on. The top bit is the sign: in a signed reading it is worth minus 2 to the power of (bits - 1).
| Bits | -1 in hex | Signed reading | Unsigned reading |
|---|---|---|---|
| 8 | FF | -1 | 255 |
| 16 | FFFF | -1 | 65535 |
| 32 | FFFF FFFF | -1 | 4294967295 |
| 64 | FFFF FFFF FFFF FFFF | -1 | 18446744073709551615 |
To negate a number by hand, flip all bits and add one. The +/− key does this, and NOT alone does the first half. The most negative value has no positive partner: -128 negated at 8 bits is -128 again, and the calculator flags it as an overflow.
Carry and overflow
Every addition, subtraction and multiplication is done exactly and then cut to the word size. The calculator compares the exact answer with what fits. In unsigned mode it reports a carry when the exact answer is outside 0 to the maximum. For a subtraction that is a borrow. In signed mode it reports an overflow when the exact answer is outside the signed range. Shifts and rotates report the last bit that fell out as carry, in either mode.
Shifts and rotates
- SHL moves bits left and fills with zeros. One step multiplies by 2 until bits fall off the top.
- SHR moves bits right and fills with zeros. One step divides an unsigned number by 2 and drops the remainder.
- SAR moves bits right and copies the sign bit. For negative numbers it rounds toward minus infinity: -7 SAR 1 is -4.
- ROL and ROR move bits round the end, so nothing is lost. The count is taken modulo the word size.
The second number is the count. A count of the word size or more empties a logical shift, and fills an arithmetic one with the sign.
RPN mode
In RPN you enter the numbers first and the operation after. The stack has four levels. X is the number on screen. An operation takes Y and X, puts the answer in X, and moves Z into Y and T into Z. T keeps its value, so a constant left there can be used again.
| You press | T | Z | Y | X |
|---|---|---|---|---|
| Type 3 | 0 | 0 | 0 | 3 |
| ENTER | 0 | 0 | 3 | 3 |
| Type 4 | 0 | 0 | 3 | 4 |
| + | 0 | 0 | 0 | 7 |
| Type 5 | 0 | 0 | 7 | 5 |
| × | 0 | 0 | 0 | 35 |
The table is (3 + 4) × 5 = 35 with no brackets. ENTER copies X up into Y and the next digit replaces the copy. Swap exchanges X and Y, drop removes X, and roll moves the whole stack down one place with X going to the top.
What you can type or paste
| Form | Meaning |
|---|---|
| 0xFF, $FF | Hex. The dollar sign is the 68000 assembler style. |
| 0b1010, %1010 | Binary. In HEX input 0b1010 is read as hex digits, because B is a digit. |
| 0o17, @17 | Octal. |
| 1111_0000, 1111 0000 | Underscores and spaces are ignored. |
| -1 | A negative number. It needs signed mode. In unsigned mode type the bit pattern in hex instead. |
A number that does not fit the word size is refused with the largest value that does. Pasting a prefixed number switches the input base to match.
Numbers this uses
- Word sizes 8, 16, 32 and 64 bits. Values are exact integers (BigInt), with no floating point anywhere.
- Signed means two's complement. A decimal number typed in signed mode must be in the signed range. A hex, octal or binary number may use any bit pattern of the word.
- Division is integer division that rounds toward zero. The remainder is shown beside it. MOD has the sign of the first number.
- The history keeps the last 12 calculations for this visit only and is not stored.
For plain conversions without arithmetic, use the number base converter. Pages for the common cases: hex calculator, binary calculator and bitwise calculator.
Nothing you type is uploaded. We count events without cookies (details).
FAQ
What is a programmer calculator?
A calculator that works on whole numbers of a fixed width, the way a CPU register does. It shows one value in hex, decimal, octal and binary at the same time, and it has the operations a programmer needs: AND, OR, XOR, NOT, shifts and rotates, plus the flags that tell you when a result did not fit.
Why does 0xFF + 1 give 0?
At 8 bits the largest unsigned value is 255. Adding 1 gives 256, which needs nine bits, so the top bit is dropped and 0 is left. The dropped bit is the carry. Switch to 16 bits and the same sum gives 0x100.
Why is 0xFF equal to -1 in 8-bit signed mode?
In two's complement the top bit counts as -128 instead of +128. 0xFF is 1111 1111, which is -128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = -1. The bits are the same in both modes. Only the reading changes, which is why the calculator keeps one bit pattern and shows both.
What is the difference between carry and overflow?
Carry says the result did not fit when the numbers are read as unsigned. Overflow says it did not fit when they are read as signed. 0xFF + 1 at 8 bits is a carry but not an overflow (-1 + 1 = 0 is right). 0x7F + 1 is an overflow but not a carry (127 + 1 does not fit, though 128 does fit an unsigned byte). The tool shows the one that matches your signed or unsigned setting.
What is the difference between SHR and SAR?
SHR is the logical shift: zeros come in from the left. SAR is the arithmetic shift: the sign bit is copied in, so a negative number stays negative. For a positive number both give the same answer. For -128 at 8 bits, SAR 1 gives -64 and SHR 1 gives 64.
What sign does MOD give?
It takes the sign of the first number, which is how C, Java and the 68000 divide: -7 MOD 3 is -1, and 7 MOD -3 is 1. Division rounds toward zero to match. In unsigned mode all values are positive, so MOD is never negative.
How does the RPN mode work?
You enter numbers first and the operation after. Type 3, press ENTER, type 4, press +. The result 7 appears in X. Four registers X, Y, Z and T hold the stack. An operation uses X and Y and moves Z and T down. The key row also has swap, drop and roll.
Are my numbers saved or sent anywhere?
No. The calculator runs in your browser. What you type is not put in the address bar, not stored and not counted. Your last word size, signed setting, base and mode are remembered on this device. A share link carries those settings, and the value on screen only if you tick the box for it.
More from FLXCode
Hex CalculatorNew
Add, subtract, multiply and divide hexadecimal numbers. Shows carry and overflow for 8, 16, 32 and 64-bit words.
Binary CalculatorNew
Add, subtract, multiply and divide binary numbers with carry and borrow. Also shows the result in hex and decimal.
Number Base ConverterNew
Convert any number between bases 2 and 36, exact with BigInt. Negative and fractional input, bits grouped by 4.
Long Division CalculatorNew
Long division laid out like on paper, with the remainder and the decimal, repeating part marked.