Binary, Decimal, Hex & Octal Converter
Type a number in any box and the others update as you type. Any size, fractions, any base from 2 to 36, two's complement for negative numbers, and every step of the working. Everything runs in your browser.
How to use this number base converter
- Type or paste a number into any box: decimal, hex, binary, octal, or the last box with any base from 2 to 36. All other boxes update as you type. Spaces, underscores and the prefixes
0x,0band0oare allowed, and#FF8800works in the hex box. - Negative numbers: type a minus sign, such as
-42. To see how a computer stores it, choose a Bit width (8, 16, 32, 64 or 128): binary, octal and hex then show the two's complement bits. With Signed ticked, a hex or binary value with the top bit set (for exampleFFin 8 bits) is read as a negative number; untick it to read the bits as unsigned. - Fractions: numbers such as
0.625or1A.8work too. When the digits never end, the box shows the first 32 and the message below the boxes shows the repeating part in brackets. - Bits: click any bit to flip it. Below the bits you see how many bits the number needs, its bytes in both byte orders, and the integer types it fits in.
- Show the working explains the conversion step by step, the same way you would do it on paper. It picks the method that fits the box you typed in; choose another one from the list.
There is no size limit for whole numbers: a 300-digit number converts exactly. Nothing you type leaves your browser.
How number bases work
A number base says how many different digits there are and how much each place is worth. In decimal (base 10) the places are worth 1, 10, 100, 1000. In binary (base 2) there are only the digits 0 and 1, and the places are worth 1, 2, 4, 8, 16. In hexadecimal (base 16) the digits are 0–9 and A–F (A = 10 … F = 15), and the places are worth 1, 16, 256, 4096. Octal (base 8) uses 0–7.
Computers work in binary. Programmers write the same bits in hex because one hex digit is exactly 4 bits, so a byte is always two hex digits: 1111 1111 = FF. Octal is used mainly for Unix file permissions such as chmod 755.
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 1 | 1 | 1 |
| 2 | 10 | 2 | 2 |
| 3 | 11 | 3 | 3 |
| 4 | 100 | 4 | 4 |
| 5 | 101 | 5 | 5 |
| 6 | 110 | 6 | 6 |
| 7 | 111 | 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 |
| 16 | 1 0000 | 20 | 10 |
| 32 | 10 0000 | 40 | 20 |
| 64 | 100 0000 | 100 | 40 |
| 100 | 110 0100 | 144 | 64 |
| 127 | 111 1111 | 177 | 7F |
| 128 | 1000 0000 | 200 | 80 |
| 255 | 1111 1111 | 377 | FF |
| 256 | 1 0000 0000 | 400 | 100 |
| 1,000 | 11 1110 1000 | 1750 | 3E8 |
| 1,024 | 100 0000 0000 | 2000 | 400 |
| 4,096 | 1 0000 0000 0000 | 10000 | 1000 |
| 65,535 | 1111 1111 1111 1111 | 177777 | FFFF |
How to convert between binary, decimal and hex by hand
Decimal to binary: divide by 2
Divide the number by 2 and write down the remainder. Divide the quotient by 2 again, and repeat until the quotient is 0. The remainders, read from the last to the first, are the binary number. For 156 the remainders are 0, 0, 1, 1, 1, 0, 0, 1, so 156 = 1001 1100. Decimal to hex works the same way with 16: 156 ÷ 16 = 9 remainder 12 (C), so 156 = 9C.
Binary to decimal: add the place values
Write the place values 1, 2, 4, 8, 16 … under the digits from the right, and add the places that have a 1. 1011 0110 = 128 + 32 + 16 + 4 + 2 = 182. For hex, multiply each digit by 1, 16, 256, 4096 …: 2F = 2 × 16 + 15 = 47.
Binary to hex and octal: group the bits
Because 16 = 24, every group of 4 bits (from the right) is one hex digit: 1001 1100 → 9 C. Because 8 = 23, every group of 3 bits is one octal digit: 10 011 100 → 2 3 4, so 156 = 234 in octal. Going back, replace every hex digit with its 4 bits.
Fractions
For the part after the point, multiply by the new base instead of dividing: 0.625 × 2 = 1.25, 0.25 × 2 = 0.5, 0.5 × 2 = 1.0, so 0.625 = 0.101 in binary. The whole-number parts of the results are the digits, read from the first to the last. Some fractions never end: 0.1 in binary is 0.0(0011), where the digits in brackets repeat forever. That is why 0.1 + 0.2 is 0.30000000000000004 in most programming languages.
Negative numbers and two's complement
Computers store a negative whole number in two's complement: to write -x in N bits, write x in binary, flip every bit and add 1. The top bit then works as the sign (1 = negative). The same bits can be read in two ways, which is why FF is 255 as an unsigned byte and -1 as a signed byte.
| Example in 8 bits | Binary | Hex |
|---|---|---|
| 5 | 0000 0101 | 05 |
| Flip every bit | 1111 1010 | FA |
| Add 1 → -5 | 1111 1011 | FB |
| -1 | 1111 1111 | FF |
| -128 (smallest) | 1000 0000 | 80 |
| Type | Bits | Signed range | Unsigned range |
|---|---|---|---|
| byte / int8 | 8 | -128 to 127 | 0 to 255 |
| short / int16 | 16 | -32,768 to 32,767 | 0 to 65,535 |
| int / int32 | 32 | -2,147,483,648 to 2,147,483,647 | 0 to 4,294,967,295 |
| long / int64 | 64 | -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 | 0 to 18,446,744,073,709,551,615 |
Base conversion in code
| Language | Text to number | Number to text |
|---|---|---|
| JavaScript | parseInt('ff', 16), BigInt('0x' + s) | n.toString(2), n.toString(16), 32-bit: (n >>> 0).toString(2) |
| Python | int('ff', 16), int('0b1010', 0) | bin(n), hex(n), oct(n), format(n, '08b'), 8-bit: format(n & 0xFF, '08b') |
| Java | Integer.parseInt("ff", 16), new BigInteger(s, 36) | Integer.toBinaryString(n), Integer.toHexString(n), Integer.toString(n, 36) |
| C# | Convert.ToInt32("ff", 16) | Convert.ToString(n, 2), n.ToString("X") |
| C / C++ | strtol(s, NULL, 16) | printf("%x %o", n, n), std::bitset<8>(n).to_string() |
| Go | strconv.ParseInt(s, 16, 64) | strconv.FormatInt(n, 2), fmt.Sprintf("%b %x %o", n, n, n) |
| Bash | echo $((16#ff)), echo $((2#1010)) | printf '%x %o\n' 255 255, echo 'obase=2; 255' | bc |
Java toHexString and toBinaryString print negative numbers as their 32-bit two's complement, while Python bin(-5) prints -0b101. Mask with & 0xFF (or the width you need) to get the bits.
Frequently asked questions
How do I convert binary to decimal?
Multiply each binary digit by its place value and add the results. The place values are powers of 2 counted from the right: 1, 2, 4, 8, 16, 32, 64, 128 and so on. For 1011 0110 that is 128 + 32 + 16 + 4 + 2 = 182. Type a binary number above to see every step.
How do I convert decimal to binary?
Divide the number by 2 again and again and write down each remainder (0 or 1) until the quotient is 0. Read the remainders from the last one to the first one. 156 gives the remainders 0, 0, 1, 1, 1, 0, 0, 1, so 156 is 1001 1100 in binary.
How do I convert hex to decimal?
Each hex digit is worth 16 times the digit on its right, and the letters A to F stand for 10 to 15. For 2F: 2 × 16 + 15 = 47. For FF: 15 × 16 + 15 = 255. Hex is popular because one hex digit is exactly 4 bits, so two hex digits are one byte.
What is 255 in binary and hex?
255 is 1111 1111 in binary, FF in hex and 377 in octal. It is the largest number that fits in one byte (8 bits), which is why it appears in IP addresses, RGB colours such as #FFFFFF and many file formats.
What is two's complement?
Two's complement is how computers store negative whole numbers. To write -x in N bits, write x in binary, flip every bit and add 1. In 8 bits, -5 is 1111 1011 (FB in hex) and -1 is 1111 1111. Choose a bit width above to see the two's complement form, and tick Signed to read a hex or binary value as a negative number.
Why is 0.1 not exact in binary?
A binary fraction can only be a sum of 1/2, 1/4, 1/8 and so on. 0.1 is not such a sum, so in binary its digits repeat forever: 0.0001100110011… or 0.0(0011). Computers cut it off after 52 bits, which is why 0.1 + 0.2 gives 0.30000000000000004 in JavaScript, Python and most other languages.
What do 0x, 0b and 0o mean?
They are prefixes that say which base a number is written in: 0x for hexadecimal (0xFF), 0b for binary (0b1010) and 0o for octal (0o755). Each box here accepts its own prefix, and the decimal box also recognises 0x, 0b and 0o and converts from that base. Spaces and underscores, as in 1111_0000, are ignored.