Number Base Converter (Binary, Octal, Decimal, Hex)
Enter one number to see it in binary, octal, decimal and hexadecimal at once. Any base from 2 to 36 works as input. Binary is grouped in fours.
Prefixes such as 0x or 0b and spaces are ignored. For negative numbers use the two's complement calculator.
How the conversion works
To go from decimal to binary, keep dividing by 2 and read the remainders from bottom to top. To go from binary to hex, split the bits into groups of four from the right and turn each group into one digit 0–F (1100 1010 → CA). Octal uses groups of three.
Worked example: base 4 1230 to decimal
- In base 4, the place values of 1230 are 1, 4, 16 and 64 from the right.
- 1×64 + 2×16 + 3×4 + 0×1 = 108
- Pick 'Base 4' above and enter 1230 to get the same value, and binary 110 1100.
Worked example: 202 in binary, hex and octal
- Divide by 2 repeatedly and write down the remainders.202 ÷ 2 = 101 … 0101 ÷ 2 = 50 … 150 ÷ 2 = 25 … 025 ÷ 2 = 12 … 112 ÷ 2 = 6 … 06 ÷ 2 = 3 … 03 ÷ 2 = 1 … 11 ÷ 2 = 0 … 1
- Read the remainders from bottom to top: 1100 1010
- Split into groups of four for hex: 1100 = C, 1010 = A → 0xCA
- Split into groups of three for octal: 011 001 010 → 0o312
Number bases from 0 to 15
| 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 |
Using it in practice
Step by step
- Type the number in the field for the base you have; prefixes such as 0x and 0b are accepted.
- Read it in every other base at once, with the binary split into groups of four.
- For an unusual base (2 to 36), use the custom base field.
Common mistakes
- Dropping leading zeros in register values. 0x0F and 0xF are the same number, but in an 8-bit register you usually want all eight bits written out: 0000 1111.
- Treating a negative number as unsigned. Converting −5 to binary needs a word size and a signed format. Use the two's complement calculator for that.
- Expecting decimal fractions to convert exactly. 0.1 in decimal has no finite binary form, which is why floating-point sums like 0.1 + 0.2 are slightly off.
Converting by hand
Each hex digit is exactly four bits, so hex to binary is a lookup, not a calculation: 0xA7 is 1010 0111. Octal works the same way with groups of three bits. For decimal to binary by hand, divide by 2 repeatedly and read the remainders from bottom to top. Datasheets often write binary with a trailing b (1010b) and hex with a trailing h (A7h).
Worked example: an I²C address in three bases
A sensor datasheet gives its 7-bit I²C address as 0x48. In binary that is 100 1000, and in decimal 72. On the wire the address is followed by a read or write bit, so the first byte is the address shifted left by one: 1001 0000 (0x90) for a write and 1001 0001 (0x91) for a read. Logic analyzers and some libraries show 0x90 and 0x91, others show 0x48, which is the usual reason a scan "finds" a device at an address that seems wrong.
Octal survives mostly in file permissions: 755 splits into 111 101 101, which is read, write and execute for the owner, and read and execute for everyone else.
Fractions in binary
Fractions convert by multiplying by 2 and keeping the integer part each time. For 0.625: 1.25 gives 1, 0.5 gives 0, and 1.0 gives 1 and ends, so 0.625 is 0.101 in binary (one half plus one eighth). For 0.1 the steps never end: 0.0001 1001 1001 … repeats forever, so any finite binary format stores it slightly wrong. Fixed-point formats used in ADCs and DSP code avoid surprises by choosing a scale such as 1 count = 0.0625, which is exactly 2 to the power −4.
Frequently asked questions
How do I convert binary to hexadecimal quickly?
Split the binary number into groups of four bits from the right and replace each group with one hex digit: 1100 1010 becomes CA. Pad the leftmost group with zeros if needed.
Why do programmers use hexadecimal?
One hex digit is exactly four bits, so a byte is always two hex digits. It is far easier to read 0xCA than 11001010 while still mapping directly onto the bits.