How number bases work
A number base says how many different digits a number system uses and how much each position is worth. In decimal, base 10, the digits are 0 to 9 and each place is worth ten times the place to its right: 255 is 2 × 100 + 5 × 10 + 5 × 1. Binary, base 2, uses only 0 and 1, and each place is worth twice the one to its right: 11111111 is 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1, which is again 255. Hexadecimal, base 16, needs six more digits and uses the letters A to F for 10 to 15, so 255 is FF. Octal, base 8, uses 0 to 7, and 255 is 377.
The same idea works for any base. Base 36 uses all ten digits and all 26 letters, which makes it the largest base you can write with plain letters and digits. It turns long numbers into short codes: 255 is 73 in base 36. JavaScript's toString() and parseInt() accept the same range of bases, 2 to 36.
Converting by hand
From decimal to another base, divide by the base again and again and keep the remainders. Read them from the last one to the first. For 156 in binary: 156, 78, 39, 19, 9, 4, 2 and 1 leave the remainders 0, 0, 1, 1, 1, 0, 0 and 1, so 156 is 10011100. The fraction part works the other way: multiply it by the base, and each whole part you get is the next digit after the point.
From another base to decimal, multiply each digit by its place value and add them up. 1F in hex is 1 × 16 + 15 × 1 = 31. The Step by step section under the converter writes out both directions for the number you type.
Between binary, octal and hex there is a shortcut, because 8 and 16 are powers of 2. Each hex digit is exactly 4 bits and each octal digit is exactly 3 bits, so you can swap digit groups without going through decimal. 1010 1111 in binary is AF in hex. The chmod calculator uses the same 3-bit groups to turn Linux file permissions like rwxr-xr-x into 755.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0000 | 0 | 0 |
| 1 | 0001 | 1 | 1 |
| 2 | 0010 | 2 | 2 |
| 3 | 0011 | 3 | 3 |
| 4 | 0100 | 4 | 4 |
| 5 | 0101 | 5 | 5 |
| 6 | 0110 | 6 | 6 |
| 7 | 0111 | 7 | 7 |
| 8 | 1000 | 10 | 8 |
| 9 | 1001 | 11 | 9 |
| 10 | 1010 | 12 | A |
| 11 | 1011 | 13 | B |
| 12 | 1100 | 14 | C |
| 13 | 1101 | 15 | D |
| 14 | 1110 | 16 | E |
| 15 | 1111 | 17 | F |
Prefixes and digit groups
Code marks the base with a prefix. JavaScript and Python both use 0b for binary, 0o for octal and 0x for hexadecimal, so 0b11111111, 0o377 and 0xFF are all 255. Both languages also let you group digits with underscores, like 1_000_000 or 0b1010_0001. Python does not allow a decimal number with a leading zero such as 0123, to avoid confusion with an old octal style.
The converter accepts the prefix of each field, plus spaces, underscores and apostrophes between digits, and commas as thousands separators in the decimal field. If you paste 0xFF into the decimal field, it tells you and offers to move the number to the hex field. With Group digits on, results are split into blocks of 4 for binary and hex and blocks of 3 for octal and decimal.
Fractions and repeating digits
Fractions convert too. The digits after the point are worth one half, one quarter and so on in binary, or one sixteenth, one 256th and so on in hex. A fraction ends in a base only if its reduced denominator divides a power of that base; the fraction calculator reduces a fraction to lowest terms. One quarter is 0.01 in binary, but one tenth has the factor 5 in its denominator, so in binary it never ends: 0.0(0011). The digits in parentheses repeat forever.
This is why JavaScript, whose numbers are 64-bit IEEE 754 doubles, prints 0.30000000000000004 for 0.1 + 0.2: neither 0.1 nor 0.2 can be stored exactly in binary. The converter works with exact fractions instead, so you see the true repeating pattern. You can also type repeating digits in parentheses, like 0.(3) for one third, and convert them to any base.
Negative numbers and two's complement
On paper a negative number just gets a minus sign, and that is what the fields show: -42 is -101010 in binary. JavaScript's toString(2) does the same; it does not return the two's complement. Fixed-width integer types store the sign inside the bits instead. Java, for example, defines its byte, short, int and long types as 8, 16, 32 and 64-bit signed two's complement integers. To write -x, flip all the bits of x and add 1. In 8 bits, 42 is 00101010, flipped 11010101, plus 1 gives 11010110.
The same bit pattern means two different numbers depending on how you read it: 11010110 is -42 as a signed byte and 214 as an unsigned one. Pick 8, 16, 32 or 64 bits under Two's complement to see the pattern, its hex form and both readings. A width of n bits holds signed values from -2n-1 to 2n-1 - 1, so 8 bits hold -128 to 127, and unsigned values from 0 to 2n - 1, so 0 to 255.
How to use the number base converter
- 1Type a number in the field of its base: decimal, binary, hexadecimal, octal, or any base from 2 to 36 in the last field. Prefixes, spaces and a minus sign are fine.
- 2Read the other bases as you type. Turn on prefixes, digit groups or uppercase letters, and copy any value with the button in its field.
- 3For whole numbers, choose a two's complement width or open the bit view. Under Step by step, see how the conversion is done by hand.
Frequently asked questions
How do I convert decimal to binary?
Divide the number by 2 again and again and write down each remainder. Reading the remainders from the last to the first gives the binary number. For 13: 13 ÷ 2 = 6 remainder 1, 6 ÷ 2 = 3 remainder 0, 3 ÷ 2 = 1 remainder 1, 1 ÷ 2 = 0 remainder 1, so 13 is 1101. The Step by step section shows this for any number you type.
How do I convert hex to binary?
Replace each hex digit with its 4 binary digits: 0 is 0000, 9 is 1001, A is 1010 and F is 1111. So 2F is 0010 1111, or 101111 without the leading zeros. Octal works the same way with groups of 3 bits. The table in the guide lists all 16 hex digits.
Why does 0.1 never end in binary?
A fraction ends in a base only when its denominator, fully reduced, divides a power of that base. 0.1 is 1/10, and 10 has the factor 5, which no power of 2 contains. So in binary the digits 0011 repeat forever: 0.0(0011). That is why a binary floating-point number, such as a JavaScript number, holds 0.1 slightly rounded.
What is two's complement?
It is a way to store negative whole numbers in a fixed number of bits, used for example by Java's int and long types. To get -x, flip every bit of x and add 1. In 8 bits, 42 is 00101010 and -42 is 11010110, which is also 214 when read as unsigned. Choose 8, 16, 32 or 64 bits in the converter to see the pattern and both readings.
What do 0x, 0b and 0o mean?
They are prefixes that mark the base of a number in code: 0x for hexadecimal, 0b for binary and 0o for octal, as in JavaScript and Python. 0xFF, 0b11111111 and 0o377 are all 255. The converter accepts them in the matching field and can add them to every result.
What is the largest number it can convert?
There is no fixed limit: whole numbers are handled as BigInt, so a number with thousands of digits converts exactly. Fractions are exact too. When a repeating block is very long, the result shows the first digits followed by an ellipsis.
Is my number sent anywhere?
No. All conversions run in your browser, and nothing you type is uploaded.