Number Base Converter
Convert numbers between different bases: binary, octal, decimal, hexadecimal.
Quick Examples
Number Systems
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 16 | 10000 | 20 | 10 |
| 255 | 11111111 | 377 | FF |
Common Uses
- Binary: Computer programming, digital electronics
- Octal: Unix file permissions
- Hexadecimal: Memory addresses, color codes, assembly
What Are Number Bases?
A number base tells you how many distinct digits a counting system uses. The everyday decimal system is base 10, using the digits 0–9. But the base is just a convention: computers count in binary (base 2, digits 0–1) because their circuits have two states, programmers write memory addresses in hexadecimal (base 16, digits 0–9 plus A–F), and older systems used octal (base 8). The converter on this page translates numbers between these systems instantly.
All positional systems share one idea: each digit's value depends on its position. In 345, the 3 means three hundreds because it sits in the hundreds place. In general, a digit d in position i (counting from 0 at the right) contributes d × baseⁱ. That single rule explains every base, and it is all the converter needs to move numbers between systems.
Conversion Methods
To convert from any base to decimal, expand the number with the positional rule and add up: each digit times the base raised to its position. To convert from decimal to another base, use repeated division: divide by the target base, record each remainder, and repeat with the quotient until it reaches zero. Reading the remainders from bottom to top gives the converted number. Hexadecimal digits above 9 use letters: A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
Step-by-Step: Decimal to Binary
- Step 1: Start with 45. Divide by 2: 45 ÷ 2 = 22 remainder 1.
- Step 2: Divide the quotient by 2: 22 ÷ 2 = 11 remainder 0.
- Step 3: Continue: 11 ÷ 2 = 5 remainder 1; 5 ÷ 2 = 2 remainder 1; 2 ÷ 2 = 1 remainder 0; 1 ÷ 2 = 0 remainder 1.
- Step 4: Read the remainders from bottom to top: 1, 0, 1, 1, 0, 1.
- Step 5: The answer is 101101 in binary. Check: 32 + 8 + 4 + 1 = 45.
Worked Examples
Example 1: Binary to decimal
Convert 1101 in binary. Expand by positions: 1×2³ + 1×2² + 0×2¹ + 1×2⁰ = 8 + 4 + 0 + 1 = 13.
Example 2: Hexadecimal to decimal
Convert 2F in hex. F stands for 15, so 2×16 + 15 = 32 + 15 = 47.
Example 3: Decimal to hexadecimal
Convert 200 to hex with repeated division by 16: 200 ÷ 16 = 12 remainder 8. The quotient 12 is the hex digit C, and reading bottom-up gives C8.
Common Mistakes
- Reading division remainders top-down instead of bottom-up, which reverses the digits.
- Forgetting that hex letters have values: A = 10 through F = 15.
- Dropping leading zeros that matter in fixed-width contexts like byte values.
- Applying decimal place values (tenths, hundredths) to fractional binary numbers, where places are halves, quarters, and eighths.
Frequently Asked Questions
Why do computers use binary?
Hardware naturally has two stable states — current flowing or not, magnetized or not. Binary maps perfectly onto those states, making circuits simple and reliable.
Why is hexadecimal so popular in programming?
One hex digit represents exactly four bits, so long binary strings become short and readable. Memory addresses, color codes like #FF5733, and byte values are all conventionally written in hex.
What is octal used for today?
Mostly Unix file permissions, where each digit packs three permission bits (read, write, execute). A permission like 755 is three octal digits.
Can bases go higher than 16?
Yes — base 32 and base 64 exist for compact encoding, using letters plus extra symbols. The positional math works identically at any base.
Common Values Reference Table
Memorizing a few landmark values makes every conversion faster, because you can anchor to the nearest known value:
| Decimal | Binary | Octal | Hex | Why it matters |
|---|---|---|---|---|
| 0 | 0 | 0 | 0 | Zero in every base |
| 8 | 1000 | 10 | 8 | First 4-bit number |
| 16 | 10000 | 20 | 10 | First 5-bit number; 10 in hex |
| 32 | 100000 | 40 | 20 | 2^5 |
| 64 | 1000000 | 100 | 40 | 2^6 |
| 128 | 10000000 | 200 | 80 | 2^7; highest bit of a byte |
| 255 | 11111111 | 377 | FF | Maximum 8-bit value (one byte) |
| 256 | 100000000 | 400 | 100 | 2^8; first 9-bit number |
| 1024 | 10000000000 | 2000 | 400 | 2^10; one kilobyte |
| 65536 | 10000000000000000 | 200000 | 10000 | 2^16; 16-bit range size |
Number Prefixes and Digit Separators
Programming languages mark the base with a prefix so the reader knows how to interpret the digits:
| Prefix | Base | Example | Meaning |
|---|---|---|---|
| 0b | Binary | 0b1010 | 10 in decimal |
| 0o | Octal | 0o755 | 493 in decimal (Unix permission notation) |
| 0x | Hexadecimal | 0xFF | 255 in decimal |
A bare leading zero also means octal in C, C++, and Java (0755 is octal), which is why JavaScript and Python use the explicit 0o prefix instead. Underscores may separate digits for readability in many languages: 0b1111_0000 is the same as 0b11110000.
Shortcut: Binary and Hex Convert Directly
Because 16 = 2^4, one hex digit is exactly four binary bits — so binary and hex convert into each other without passing through decimal. This is the trick programmers actually use.
Hex to Binary: Expand Each Digit
Replace every hex digit with its 4-bit group. Convert 0x2F:
- 2 = 0010, F = 1111
- Put the groups together: 00101111
- Check: 32 + 8 + 4 + 2 + 1 = 47, and 2x16 + 15 = 47.
Binary to Hex: Group in Fours from the Right
Convert 101101 to hex. Pad on the left to complete groups of four: 0010 1101. Then 0010 = 2 and 1101 = D.
Binary to Octal: Group in Threes
Since 8 = 2^3, each octal digit is three bits. Convert 11110101: pad to 011 110 101, giving 3 6 5.
Fractional Numbers in Other Bases
Bases handle fractions too: digits after the point use negative powers. In binary the places are halves, quarters, eighths (1/2, 1/4, 1/8), not tenths and hundredths.
Worked Example: Binary Fraction to Decimal
Convert 101.11 in binary. Integer part: 1x4 + 0x2 + 1x1 = 5. Fraction part: 1x(1/2) + 1x(1/4) = 0.5 + 0.25 = 0.75.
Worked Example: Decimal Fraction to Binary
Convert 0.625 to binary by repeated multiplication: multiply the fraction by 2 and record each integer part.
- 0.625 x 2 = 1.25, record 1
- 0.25 x 2 = 0.5, record 0
- 0.5 x 2 = 1.0, record 1
- Result: 0.101. Check: 0.5 + 0.125 = 0.625.
Bases Beyond 16
The positional math works at any base. Bases above 16 reuse the alphabet: in base 36, A = 10 through Z = 35. Example: 1Z in base 36 = 1x36 + 35 = 71 in decimal. Base 32 and base 64 are used for compact data encoding, and base 36 appears in URL shorteners. The converter's four bases (2, 8, 10, 16) cover the ones used in everyday programming and electronics.
Powers of Two Reference
| Power | Value | Power | Value |
|---|---|---|---|
| 2^0 | 1 | 2^9 | 512 |
| 2^1 | 2 | 2^10 | 1024 |
| 2^2 | 4 | 2^11 | 2048 |
| 2^3 | 8 | 2^12 | 4096 |
| 2^4 | 16 | 2^13 | 8192 |
| 2^5 | 32 | 2^14 | 16384 |
| 2^6 | 64 | 2^15 | 32768 |
| 2^7 | 128 | 2^16 | 65536 |
| 2^8 | 256 |
The number of bits needed for a value N is the smallest n with 2^n > N. For 500: 2^8 = 256 is too small, 2^9 = 512 fits, so 9 bits are needed. An n-bit unsigned number ranges from 0 to 2^n - 1.
Real-World Applications
| Application | Base used | Example |
|---|---|---|
| Unix file permissions | Octal | chmod 755: 7 = 111 (rwx), 5 = 101 (r-x), 5 = 101 (r-x) |
| Web colors | Hexadecimal | #FF5733: FF red, 57 green, 33 blue |
| Memory addresses | Hexadecimal | 0x7FFF: compact for long binary addresses |
| IP subnetting | Binary | Subnet masks like 255.255.255.0 are bit patterns |
| Character encoding | Decimal/Hex | ASCII 65 = 0x41 = the letter A |
| Digital logic design | Binary | FPGA and circuit work happens bit by bit |
Quick Conversion Cheat Sheet
- Any base to decimal: multiply each digit by base^position and sum.
- Decimal to any base: repeated division, read remainders bottom to top.
- Binary to hex: group bits in fours from the right, convert each group.
- Hex to binary: expand each hex digit to 4 bits.
- Binary to octal: group bits in threes from the right, convert each group.
- Decimal fraction to binary: repeated multiplication by 2, read integer parts top to bottom.