Programmer calculators
Add and multiply in binary and hex, store negative numbers in a fixed number of bits, read floats, and simplify logic. Each calculator shows its working.
In decimal that is 11 + 6 = 17
In decimal that is 697 + 4007 = 4704
Runs in your browser. Nothing you type is uploaded.
Arithmetic in binary and hex
For sums where a column carries at 2 or at 16.
Signed numbers and floats
For values stored in a fixed number of bits.
Logic and Boolean algebra
For expressions, truth tables and circuits.
How big a number fits in 8, 16, 32 or 64 bits
Signed types give up one bit for the sign, so their top value is about half the unsigned one.
| Bits | Unsigned range | Signed range | Signed max in hex |
|---|---|---|---|
| 8 | 0 to 255 | -128 to 127 | 7F |
| 16 | 0 to 65,535 | -32,768 to 32,767 | 7FFF |
| 32 | 0 to 4,294,967,295 | -2,147,483,648 to 2,147,483,647 | 7FFFFFFF |
| 64 | 0 to 18,446,744,073,709,551,615 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 7FFFFFFFFFFFFFFF |
What happens when you go one past the top
The bits roll over and the sign bit flips, so a signed number jumps from its maximum to its minimum.
| Type | Sum | In binary or hex | Result |
|---|---|---|---|
| 8-bit signed | 127 + 1 | 01111111 + 1 = 10000000 | -128 |
| 8-bit unsigned | 255 + 1 | FF + 1 = 100, top bit dropped | 0 |
| 32-bit signed | 2,147,483,647 + 1 | 7FFFFFFF + 1 = 80000000 | -2,147,483,648 |
What an ordinary calculator gets wrong
A phone calculator works in base 10 and keeps numbers as long as it likes. Code does neither. A column carries at 2 or 16, a negative number has to fit in 8, 16 or 32 bits, and a decimal like 0.1 cannot be stored exactly, so 0.1 + 0.2 comes out a little over 0.3.
These calculators work the way a processor does and show every step: each carry, each borrow, each flipped bit. That makes them useful for checking a hand calculation as well as for getting the answer.
Frequently asked questions
What is 2147483647?
It is the largest value a signed 32-bit integer can hold, 231 − 1, written 7FFFFFFF in hex. Many languages call it INT_MAX or Int32.MaxValue. Add 1 and a 32-bit signed value wraps to -2,147,483,648.
What is the difference between signed and unsigned integers?
An unsigned integer uses every bit for the size of the number, so 8 bits hold 0 to 255. A signed integer uses two's complement, where the top bit counts as negative, so 8 bits hold -128 to 127. Both store 256 different values; they cover a different stretch of the number line.
What is integer overflow?
Overflow happens when a result needs more bits than the type has. The extra bit is dropped and the value wraps around, so 255 + 1 in an unsigned byte gives 0. In C, overflow of a signed integer is undefined behavior, which means the compiler is free to assume it never happens.