How the number base converter works
Convert whole numbers between binary, octal, decimal, hexadecimal and any base from 2 to 36. Numbers of any length convert exactly, and a place-value table shows how the digits add up.
Formula
Value = Σ digit × base^position, counting positions from 0 at the right. To write a value in a new base, divide by the base again and again; the remainders, read from last to first, are the digits.
- 1
Enter the number and its base
The starting example is 255 in decimal.
- 2
Divide by the new base
255 ÷ 16 = 15 remainder 15, and 15 ÷ 16 = 0 remainder 15.
- 3
Write the remainders as digits
15 is the digit F in hexadecimal, so 255 = FF.
- 4
Check the other bases
The same value is 1111 1111 in binary (8 bits) and 377 in octal.
Worked example
The calculator opens with these values
- Number
- 255
- From
- Decimal (base 10)
- To
- Hexadecimal (base 16)
In hexadecimal (base 16)
FF
Common numbers in binary, octal and hex
Powers of two are round numbers in binary and hex: 16 is 10 in hex and 128 is 1000 0000 in binary. In code, 0b marks binary, 0o octal and 0x hexadecimal; the converter accepts these prefixes when the matching base is chosen, so 0xFF reads as FF.
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 4 | 100 | 4 | 4 |
| 8 | 1000 | 10 | 8 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 1 0000 | 20 | 10 |
| 32 | 10 0000 | 40 | 20 |
| 64 | 100 0000 | 100 | 40 |
| 100 | 110 0100 | 144 | 64 |
| 128 | 1000 0000 | 200 | 80 |
| 255 | 1111 1111 | 377 | FF |
How many values fit in 8, 16, 32 and 64 bits
n bits hold 2ⁿ different values. Unsigned, they run from 0 to 2ⁿ − 1. Signed (two's complement), the top bit carries the sign, so the range is split around zero. This is why a byte holds 0 to 255, and why a 32-bit counter stops at 4,294,967,295.
| Bits | Name | Largest unsigned value | In hex | Signed range |
|---|---|---|---|---|
| 4 | Nibble | 15 | F | −8 to 7 |
| 8 | Byte | 255 | FF | −128 to 127 |
| 16 | 16-bit | 65,535 | FFFF | −32,768 to 32,767 |
| 32 | 32-bit | 4,294,967,295 | FFFFFFFF | −2,147,483,648 to 2,147,483,647 |
| 64 | 64-bit | 18,446,744,073,709,551,615 | FFFFFFFFFFFFFFFF | −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
Reading hex color codes
Web colors are three bytes written in hex, #RRGGBB: one pair of digits each for red, green and blue, from 00 (none) to FF (255, full strength).
- #FF0000 is pure red, #FFFFFF is white and #000000 is black.
- #808080 is a mid gray: hex 80 is 128, about half of 255, on every channel.
- The three-digit form doubles each digit, so #F80 is #FF8800, an orange.
- An eight-digit code adds transparency as a fourth pair: #FF000080 is red at about 50% opacity.
Common questions
How do I convert binary to decimal?
Multiply each bit by its place value, 1, 2, 4, 8 and so on from the right, and add them. 1011 = 8 + 0 + 2 + 1 = 11. Choose From binary and To decimal to see each step in the place-value table.
Why do hexadecimal numbers use letters?
Base 16 needs sixteen digits, so after 0 to 9 it uses A = 10, B = 11, up to F = 15. One hex digit stands for exactly four bits, which is why colours and memory addresses are written in hex.
Can it convert very large numbers?
Yes. The converter works with whole numbers of any size up to 200 characters, beyond the 9,007,199,254,740,991 limit of ordinary JavaScript numbers, so 64-bit values such as FFFFFFFFFFFFFFFF convert exactly.
Related calculators
Roman Numeral Converter
Numbers 1 to 3,999 to Roman numerals and back, strictly checked
Data Storage Converter
Convert between bytes, KB, MB, GB, and TB
Scientific Calculator
Trig, logs, roots, powers, factorials and Ans with an on-screen keypad
Exponent Calculator
Calculate powers and exponential expressions