Programmer's calculator
Integer expressions with hex, binary, and octal; 8- to 128-bit words; signed or unsigned; bitwise operators, rotates, and a clickable bit grid; an n-bit overflow clock with signed and unsigned labels; and what n bits hold, with the KB versus KiB gap.
Added · updated 14 October 2026
How to use it
Type an expression; the result updates as you type, in every base at once.
-
Literals:
255,0xff,0b1111_1111,0o377,'A'(a character’s code), with_separators. Switch Bare numbers are to HEX to typeffwithout the prefix. -
Operators:
+ - * / % **,& | ^ ~,<< >> >>>and parentheses, with JavaScript precedence.>>is arithmetic in signed mode and logical in unsigned mode;>>>is always logical. -
Functions:
rotl(x, n),rotr(x, n),popcnt,clz,ctz,bswap,brev,sext(x, bits),mask(n),bit(n),min,max,abs,pow,sqrt(integer),gcd,lcm. -
Variables:
ans(the last saved result) andm(memory: M+, M−, MR, MC). -
Word size and sign: arithmetic is exact, then wrapped to the chosen width in two’s complement. A note appears when the exact result did not fit.
-
Bits: click any bit to toggle it; the buttons shift, rotate, negate, invert, byte-swap, or bit-reverse the current value by n.
-
Keyboard: Enter saves the result to the history, ↑ and ↓ walk the history, Esc clears.
Overflow clock
A fixed-width integer lives on a circle, not a line. Pick n from 3 to 8 bits: the clock has 2ⁿ positions, each labelled with its bit pattern, its unsigned value (u) and its two’s-complement value (s). + 1 steps clockwise, − 1 anticlockwise; Add or Multiply applies the amount. The blue line between 2ⁿ − 1 and 0 is the unsigned wrap (the carry out of the top bit is lost); the red line between 2ⁿ⁻¹ − 1 and −2ⁿ⁻¹ is signed overflow. The line the hand crosses flashes, and the panel gives the true result next to what the register keeps — the true result mod 2ⁿ. Multiplication wraps the same way. Click any position to move the hand there.
Bits & bytes
What n bits can hold: slide n from 1 to 128 for the number of patterns 2ⁿ (exact), the unsigned and signed ranges, how much memory an n-bit pointer can address, and a comparison ("more than the seconds since the Big Bang"; the comparisons are rough published estimates).
KB versus KiB: type a size in any unit — B, kB (or KB), KiB, MB, MiB … EB, EiB — to see it in every decimal and binary unit, with the "2 TB drive shows as 1.82 TiB" sentence and a chart of the gap 1.024ᵏ − 1 (2.4% for kilo, growing to 15.3% for exa). Here KB means 1000 bytes, as the SI prefix says.
Limits
The overflow clock covers 3 to 8 bits, amounts from −999 to 999. Sizes use JavaScript numbers, so conversions are exact to about 15 significant digits.
Companion to two’s complement and overflow (chapter 1) and powers of two (chapter 3) of Mathematics, Reconnected.
The Bits & bytes tab also serves the KV-cache sizes in Inference: two very different phases (part IV) of _AI Acceleration: From Transistors to Trillion-Parameter Models, where MB and MiB differ by 4.9%.
Linking to an example
Share link copies a URL that opens this tool exactly as you have it, on the tab you are using.
Hand-written links work too; add the tab after # (calc, clock or bytes) or let the
parameters choose it.
| Parameter | Meaning | Example |
|---|---|---|
|
Calculator: the expression |
|
|
word size: 8, 16, 32, 64 or 128 |
|
|
|
|
|
how bare numbers are read: 10, 16, 8 or 2 |
|
|
Overflow clock: n, 3 to 8 |
|
|
where the hand starts (signed or unsigned; wrapped) |
|
|
the amount, and |
|
|
apply the amount this many times on opening |
|
|
Bits & bytes: bit width 1 to 128 |
|
|
Bits & bytes: a size and its unit (B, kB, KiB, MB, MiB, …) |
|
|
a book example (below) |
|
In expr, a ` typed by hand means plus — `?expr=2147483647+1&width=32` adds — while `%2B` always
means plus and `%20` a space. (Links the tool makes encode plus as `%2B`, so older shared links,
where ` stood for a space, still open as before.) For example
?expr=0xDEAD_BEEF%20%3E%3E%204&width=32&base=16.
Examples from Mathematics, Reconnected (?example=<name>):
example= |
Shows |
|---|---|
|
the 4-bit clock after 7 + 1: the hand crosses the signed boundary to −8 |
|
0 − 3 in 4 bits: pattern 1101, unsigned 13, signed −3 |
|
3 × 6 = 18 is stored as 2 in 4 bits: multiplication wraps too |
|
the 8-bit clock after 127 + 1 = −128 |
|
−5 in 8 bits: 1111 1011 = FB, unsigned 251 |
|
2147483647 + 1 in 32 bits is −2147483648 |
|
−1 as an unsigned 32-bit value: 4294967295 (why |
|
a "2 TB" drive is 1.82 TiB; the gap per prefix |
|
32 bits: 4,294,967,296 patterns, a 4 GiB address space |
|
64 bits: about 1.8 × 10¹⁹ patterns, a 16 EiB address space |
Examples from AI Acceleration (the AI primer):
example= |
Shows |
|---|---|
|
a 70B model’s KV cache per token (2 × 80 layers × 8 KV heads × 128 × 2 bytes = 327,680 bytes): 0.3125 MiB, which is 0.33 MB — "0.31 MB" mixes the two (open) |
|
8,192 tokens of it: exactly 2.5 GiB, or 2.68 GB (open) |
|
131,072 tokens: 40 GiB, or 42.9 GB, for one sequence (open) |
Feedback is a gift. Something to improve, a feature to add, or a bug? Tell me.
Runs entirely in your browser; nothing you type leaves this page.