This number system converter changes a number between the four bases you meet in computer science: binary (base 2), octal (base 8), decimal (base 10) and hexadecimal (base 16). Type the number once and read all four answers together.
How to use the number system converter
- Pick the base of the number you have: Binary, Octal, Decimal or Hexadecimal.
- Type the number. Spaces, underscores and a 0b, 0o or 0x prefix are fine.
- Read the value in every base. Use Copy next to the one you need.
- For a non-decimal input, the place value working below shows how the decimal value was found.
When you switch the input base, the current number is converted for you, so nothing is lost.
The four number systems
| System | Base | Digits used | Example (value 255) |
|---|---|---|---|
| Binary | 2 | 0, 1 | 11111111 |
| Octal | 8 | 0 to 7 | 377 |
| Decimal | 10 | 0 to 9 | 255 |
| Hexadecimal | 16 | 0 to 9, A to F | FF |
Number system conversion formula
Value = Sum of (Digit × Base^position)
Position 0 is the rightmost digit. For hexadecimal, A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Example, hex 2F to decimal: 2 × 16 + 15 × 1 = 47.
Decimal to binary, octal and hex
Divide by the new base again and again, and write the remainders. Read them from bottom to top.
| Step | 156 ÷ 16 | 9 ÷ 16 |
|---|---|---|
| Quotient | 9 | 0 |
| Remainder | 12 (C) | 9 |
Reading from the bottom: 156 in hex is 9C. The same method with 2 gives 10011100, and with 8 gives 234.
Common mistake: A common mistake is reading the remainders from top to bottom. That would give C9 here. The last remainder is the leftmost digit.
Shortcut between binary, octal and hex
Since 8 = 2³ and 16 = 2⁴, you can skip decimal:
- Binary to hex: group bits in fours from the right. 1001 1100 is 9 C, so 9C.
- Binary to octal: group bits in threes from the right. 10 011 100 is 2 3 4, so 234.
- Hex to binary: write each hex digit as 4 bits. F3 is 1111 0011.
This is why programmers use hex for memory addresses and colours. Two hex digits are exactly one byte.
Where you will use this
- Colour codes in CSS, such as #FF8800, are three hex bytes for red, green and blue. Try them in the CSS tutorial.
- File permissions in Linux, such as 755, are octal.
- Placement tests often ask base conversions. Practise with these aptitude questions.
- To write the conversion as a program, see convert a decimal number to binary and binary to decimal in Java.
Pro tip: Remember that hex F is binary 1111 and hex 8 is binary 1000. With those two, you can work out most other hex digits in your head.
This converter handles whole numbers up to 200 digits exactly. To convert text characters into bits instead of numbers, use the text to binary converter.
