Number Base Converter
Convert between binary, decimal, octal, and hexadecimal.
Understanding Number Systems
A number system (or numeral system) is a writing system for expressing numbers. Different number systems use different bases, which represent how many unique digits are used to represent numbers. The most common systems are binary (base 2), octal (base 8), decimal (base 10), and hexadecimal (base 16).
Decimal (Base 10)
The decimal system is what we use in everyday life. It uses 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. Each position represents a power of 10.
Example: 365 = (3 × 10²) + (6 × 10¹) + (5 × 10⁰)
= (3 × 100) + (6 × 10) + (5 × 1) = 300 + 60 + 5
Binary (Base 2)
Binary uses only two digits: 0 and 1. It's the foundation of all digital computers and electronics. Each position represents a power of 2.
Example: 1011₂ = (1 × 2³) + (0 × 2²) + (1 × 2¹) + (1 × 2⁰)
= (1 × 8) + (0 × 4) + (1 × 2) + (1 × 1) = 8 + 0 + 2 + 1 = 11₁₀
Why Computers Use Binary
- Simple electronics: On/off, high/low voltage states
- Reliable: Easy to distinguish between two states
- Fast operations: Simple logic gates
- Error detection: Easier to detect transmission errors
Octal (Base 8)
Octal uses eight digits: 0, 1, 2, 3, 4, 5, 6, 7. Each position represents a power of 8. It was popular in early computing as a shorthand for binary (3 binary digits = 1 octal digit).
Example: 75₈ = (7 × 8¹) + (5 × 8⁰)
= (7 × 8) + (5 × 1) = 56 + 5 = 61₁₀
Hexadecimal (Base 16)
Hexadecimal uses sixteen digits: 0-9 and A-F (where A=10, B=11, C=12, D=13, E=14, F=15). Each position represents a power of 16. It's commonly used in computing because 4 binary digits = 1 hex digit.
Example: 2F₁₆ = (2 × 16¹) + (15 × 16⁰)
= (2 × 16) + (15 × 1) = 32 + 15 = 47₁₀
Conversion Table
| Decimal | Binary | Octal | Hexadecimal |
|---|---|---|---|
| 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 |
| 16 | 10000 | 20 | 10 |
Real-World Applications
Programming and Computer Science
- Memory addresses: Often displayed in hexadecimal
- Colors: RGB colors in hex (#FF5733 = Red: FF, Green: 57, Blue: 33)
- File permissions: Unix/Linux uses octal (755, 644)
- IP addresses: IPv6 uses hexadecimal
- Binary data: File formats, network protocols
Web Development
#FF0000 = Red (FF=255 red, 00=0 green, 00=0 blue)
#00FF00 = Green
#0000FF = Blue
Networking
MAC addresses use hexadecimal: 00:1A:2B:3C:4D:5E
IPv6 addresses use hexadecimal: 2001:0db8:85a3:0000:0000:8a2e:0370:7334
Quick Conversion Methods
Binary to Hexadecimal
Group binary digits into sets of 4, starting from the right:
Example: 11010110₂
Group: 1101 0110
Convert: D 6 = D6₁₆
Hexadecimal to Binary
Convert each hex digit to 4 binary digits:
Example: A3₁₆
A = 1010, 3 = 0011
Result: 10100011₂
Common Programming Prefixes
| Base | Prefix | Example |
|---|---|---|
| Binary | 0b | 0b1010 = 10 |
| Octal | 0o or 0 | 0o12 = 10 |
| Decimal | None | 10 = 10 |
| Hexadecimal | 0x | 0xA = 10 |
Binary Operations
Understanding binary is essential for bitwise operations in programming:
- AND (&): Both bits must be 1
- OR (|): At least one bit must be 1
- XOR (^): Bits must be different
- NOT (~): Inverts all bits
- Shift (<<, >>): Moves bits left or right
Powers Reference
Binary (Base 2):
- 2⁰ = 1
- 2¹ = 2
- 2² = 4
- 2³ = 8
- 2⁴ = 16
- 2⁵ = 32
- 2⁶ = 64
- 2⁷ = 128
- 2⁸ = 256
Hexadecimal (Base 16):
- 16¹ = 16
- 16² = 256
- 16³ = 4,096
Hex Digits
- A = 10
- B = 11
- C = 12
- D = 13
- E = 14
- F = 15