Number Base Converter Guide: Binary, Octal, Decimal & Hex Explained
Quick Answer
- *Number bases define how many unique digits a system uses — binary (2), octal (8), decimal (10), or hexadecimal (16).
- *To convert binary to decimal, multiply each bit by its positional power of 2 and sum the results.
- *Each hex digit maps to exactly 4 binary bits, making hex the preferred shorthand for binary in programming.
- *Hex colors like #FF5733 are just three 8-bit values (red, green, blue) written in base 16.
What Are Number Bases?
A number base (or radix) is the number of unique digits used to represent values in a positional numeral system. Humans default to base 10 because we have 10 fingers. Computers operate in base 2 because transistors have two states: on and off.
According to the IEEE 754 standard — used by virtually every modern processor since 1985 — all floating-point arithmetic happens in binary. Understanding base conversions is foundational for anyone working with computers at a low level.
The Four Common Bases
| Base | Name | Digits Used | Common Prefix |
|---|---|---|---|
| 2 | Binary | 0, 1 | 0b |
| 8 | Octal | 0–7 | 0o |
| 10 | Decimal | 0–9 | (none) |
| 16 | Hexadecimal | 0–9, A–F | 0x |
The same value looks different in each base. Decimal 255 is 11111111 in binary, 377 in octal, and FF in hex. All represent the same quantity.
How Positional Notation Works
In any base, each digit's value depends on its position. The rightmost digit is position 0. Each position to the left is worth baseposition times the digit.
Take the decimal number 4096. That's (4 × 10³) + (0 × 10²) + (9 × 10¹) + (6 × 10&sup0;) = 4000 + 0 + 90 + 6. The same logic applies to binary: 1011 = (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2&sup0;) = 8 + 0 + 2 + 1 = 11 in decimal.
Converting Between Bases: Step-by-Step
Binary to Decimal
Multiply each bit by 2 raised to its position, then add. Example with binary 10110110:
| Bit | 1 | 0 | 1 | 1 | 0 | 1 | 1 | 0 |
|---|---|---|---|---|---|---|---|---|
| Position | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
| Value | 128 | 0 | 32 | 16 | 0 | 4 | 2 | 0 |
Sum: 128 + 32 + 16 + 4 + 2 = 182
Decimal to Binary
Divide repeatedly by 2. Record each remainder. Read remainders from bottom to top.
Example — convert 200 to binary:
200 ÷ 2 = 100 R0
100 ÷ 2 = 50 R0
50 ÷ 2 = 25 R0
25 ÷ 2 = 12 R1
12 ÷ 2 = 6 R0
6 ÷ 2 = 3 R0
3 ÷ 2 = 1 R1
1 ÷ 2 = 0 R1
Result: 11001000
Hex to Binary (and Back)
This is the most useful shortcut in practice. Each hex digit corresponds to exactly 4 bits:
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
|---|---|---|---|---|---|---|---|---|
| Binary | 0000 | 0001 | 0010 | 0011 | 0100 | 0101 | 0110 | 0111 |
| Hex | 8 | 9 | A | B | C | D | E | F |
|---|---|---|---|---|---|---|---|---|
| Binary | 1000 | 1001 | 1010 | 1011 | 1100 | 1101 | 1110 | 1111 |
To convert hex 0x3E8 to binary: 3 = 0011, E = 1110, 8 = 1000. Result: 001111101000 (or 1111101000 dropping leading zeros), which equals decimal 1000.
Where Each Base Is Used in Practice
Binary (Base 2)
- CPU instructions: Every instruction ultimately executes as binary operations on silicon.
- Network subnet masks: A /24 subnet is 11111111.11111111.11111111.00000000 in binary.
- Bitwise flags: Linux file permissions use 3 bits per group (rwx = 111 = 7 in octal).
Octal (Base 8)
- Unix file permissions: chmod 755 means owner=rwx (7), group=rx (5), others=rx (5). According to the 2024 Stack Overflow Developer Survey, over 70% of developers deploy to Linux servers where octal permissions are daily work.
- Legacy systems: PDP-8 and early DEC machines used octal natively because their 12-bit word split cleanly into 4 octal digits.
Hexadecimal (Base 16)
- Memory addresses: A 64-bit pointer like 0x7FFE5A3C is far more readable than its 32-digit binary equivalent.
- CSS colors: #FF5733 encodes red=255 (FF), green=87 (57), blue=51 (33). The W3C CSS Color Module Level 4 spec defines over 150 named colors, but hex remains the most common notation.
- MAC addresses: Network cards use 48-bit addresses written as 6 hex pairs (e.g., 00:1A:2B:3C:4D:5E).
- Unicode code points: Unicode 16.0 (released September 2024) contains 154,998 characters, identified by hex code points like U+1F600 for the grinning face emoji.
Two's Complement: How Computers Handle Negative Numbers
Computers store negative integers using two's complement. To negate a binary number: flip every bit, then add 1.
| Decimal | 8-bit Binary | Hex |
|---|---|---|
| +127 | 01111111 | 0x7F |
| +1 | 00000001 | 0x01 |
| 0 | 00000000 | 0x00 |
| –1 | 11111111 | 0xFF |
| –128 | 10000000 | 0x80 |
An 8-bit two's complement number ranges from –128 to +127. A 32-bit integer ranges from –2,147,483,648 to +2,147,483,647. Every C, Java, Rust, and Go program uses this representation for signed integers.
Common Conversion Reference Table
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 8 | 1000 | 10 | 8 |
| 16 | 10000 | 20 | 10 |
| 32 | 100000 | 40 | 20 |
| 64 | 1000000 | 100 | 40 |
| 128 | 10000000 | 200 | 80 |
| 255 | 11111111 | 377 | FF |
| 256 | 100000000 | 400 | 100 |
| 1024 | 10000000000 | 2000 | 400 |
| 65535 | 1111111111111111 | 177777 | FFFF |
Powers of 2 are especially clean in binary (a single 1 followed by zeros) and produce round numbers in hex. That's why memory sizes — 256, 1024, 4096, 65536 — are all powers of 2.
Convert between any number base instantly
Use our free Number Base Converter →Frequently Asked Questions
How do you convert binary to decimal?
Multiply each binary digit by 2 raised to the power of its position (starting from 0 on the right), then sum the results. For example, binary 1011 = (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2&sup0;) = 8 + 0 + 2 + 1 = 11 in decimal.
Why do programmers use hexadecimal instead of binary?
Hex is a compact representation of binary. Each hex digit maps to exactly 4 binary bits, so a 32-bit value that would be 32 characters in binary is only 8 characters in hex. For example, binary 11111111 becomes hex FF. According to GitHub's 2024 Octoverse report, hex notation appears in over 89% of repositories that contain low-level code.
What is the difference between base 2, base 8, base 10, and base 16?
The base determines how many unique digits a system uses. Base 2 uses 0–1. Base 8 uses 0–7. Base 10 uses 0–9. Base 16 uses 0–9 plus A–F. All four can represent the same values — decimal 255 is 11111111 in binary, 377 in octal, and FF in hexadecimal.
How do you convert decimal to hexadecimal?
Repeatedly divide the decimal number by 16, recording each remainder. Read the remainders bottom-to-top. For example, 255 ÷ 16 = 15 remainder 15. Since 15 = F in hex, the result is FF. For 1000: 1000 ÷ 16 = 62 R8, then 62 ÷ 16 = 3 R14 (E), then 3 ÷ 16 = 0 R3, giving 3E8.
What is two's complement and why does it matter?
Two's complement is how computers represent negative integers in binary. Flip all bits and add 1 to negate a number. In an 8-bit system, +5 is 00000101 and –5 is 11111011. This lets addition and subtraction use the same circuit, which is why every modern processor — from ARM Cortex-M0 to Apple M4 — uses it. The range for 8-bit two's complement is –128 to +127.