How positional number bases work
In a positional system each digit is multiplied by a power of the base. Decimal uses base 10 with digits 0–9; binary uses base 2 with only 0 and 1; octal uses base 8; hexadecimal uses base 16 with the digits 0–9 followed by A–F for ten to fifteen. Bases up to 36 simply continue through the alphabet to Z.
value = dₙ × bⁿ + … + d₁ × b + d₀ + d₋₁ × b⁻¹ + …
To convert a whole number to a base, divide by the base repeatedly and read the remainders from last to first. To convert a fraction, multiply the fractional part by the base repeatedly and read off the whole-number parts in order. This calculator does both with arbitrary-precision integers (JavaScript BigInt), so a 64-bit or even 128-bit value converts without the rounding that ordinary floating-point numbers suffer above 253.
Worked example: 48879 is BEEF
The default input is the decimal number 48,879. Dividing by 16 four times gives remainders 15, 14, 14 and 11, which read backwards are B, E, E, F — so 48,879 = 0xBEEF, a value programmers like to use as a memorable marker. Each hex digit maps to exactly four bits, so the binary form is 1011 1110 1110 1111 and the octal form is 137357.
| Base | 48,879 written as |
|---|---|
| 2 | 1011 1110 1110 1111 |
| 8 | 137357 |
| 16 | BEEF |
| 36 | 11PR |
The number has a bit length of 16 and contains 13 one-bits. Because 48,879 is larger than 32,767 it does not fit in a signed 16-bit integer, so the automatic bit width picks 32 bits; read as an unsigned 16-bit value the same bits would be 0xBEEF, but as signed 16-bit they would mean −16,657.
Negative numbers and two's complement
Computers store signed integers in two's complement. For an n-bit integer, a negative value −x is stored as 2ⁿ − x. In practice: write x in binary, invert every bit, then add 1. With 8 bits, −1 is 1111 1111 (0xFF), −42 is 1101 0110 (0xD6) and −128 is 1000 0000; the highest bit acts as the sign bit. The ranges are −128 to 127 for 8 bits, −32,768 to 32,767 for 16 bits, about ±2.1 billion for 32 bits and about ±9.2 × 1018 for 64 bits.
Choose a bit width to see the pattern, the bytes in big-endian and little-endian order, and how the same bits read as signed and unsigned integers. The plain base conversions above the bit view always use a minus sign (−2A in hex), which is the mathematical notation rather than a machine representation.
Fractions and text bytes
A fraction that ends in one base may repeat forever in another. Decimal 0.1 is 0.0001100110011… in binary — the block 0011 repeats — which is why 0.1 cannot be stored exactly in binary floating point. The converter detects repeating blocks and marks them with a line over the digits; when a fraction does not repeat within the digit limit it is cut and shown with “…”.
The Text ↔ bytes mode encodes text as UTF-8, the encoding used by almost every web page. ASCII letters take one byte (H = 0x48), most accented letters two, Chinese characters three (世 = E4 B8 96) and emoji four. Paste hex, binary or decimal bytes to decode them back into text; invalid UTF-8 sequences are reported instead of being silently replaced.
Frequently asked questions
How do I convert decimal to binary by hand?
Divide by 2 repeatedly and write down each remainder. Reading the remainders from the last one to the first gives the binary number: 13 → 6 r1 → 3 r0 → 1 r1 → 0 r1, so 13 = 1101.
Why is hexadecimal used so much in computing?
One hex digit is exactly four bits, so a byte is always two hex digits. Hex is a compact, readable way to write binary data such as colors (#FF8800), memory addresses and byte dumps.
What is the largest number I can convert?
There is no fixed limit for whole numbers: they are handled as arbitrary-precision integers, so 2128 − 1 converts exactly. Fractional parts are shown up to the digit limit you set (up to 200 digits).
What does FF mean as a signed byte?
Unsigned, 0xFF is 255. As a signed 8-bit two's complement value the top bit is the sign, so 0xFF is −1. Enter FF in hex and pick 8-bit to see both readings.
Sources & references
Last reviewed: