Complete Guide to Positional Number Bases & Conversion
In digital computing, computer science, and data engineering, numeric values are stored as electronic signals in distinct numeral bases. Converting accurately between Binary (base 2), Octal (base 8), Decimal (base 10), and Hexadecimal (base 16) is a core foundation for low-level software design, network payload inspection, memory dump analysis, and hardware programming.
1. Understanding Positional Number Systems
- Binary (Base 2): Consists only of bits
0and1. Each column represents an escalating power of 2 ($2^0, 2^1, 2^2, 2^3, \dots$). It corresponds directly to digital logic high/low voltages. - Octal (Base 8): Uses digits
0through7. Because $2^3 = 8$, each octal digit maps neatly to exactly 3 binary bits. It remains widely used in Unix and Linux file permission strings (e.g.chmod 755). - Decimal (Base 10): The universal human counting system utilizing digits
0through9based on powers of 10. - Hexadecimal (Base 16): Uses digits
0–9followed by lettersA–F(where A=10, B=11, C=12, D=13, E=14, F=15). Since $2^4 = 16$, each hexadecimal character represents exactly 4 binary bits (one nibble). Hex is the industry standard for memory addresses, IPv6 packets, SHA/MD5 hashes, and RGB web colors (e.g.,#3B82F6).
2. Number Base Equivalence Table (0 to 15 / 0 to F)
| Decimal (Base 10) | Binary (Base 2 - 4 bits) | Octal (Base 8) | Hexadecimal (Base 16) |
|---|---|---|---|
| 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 |
3. Manual Conversion Methods
Hexadecimal to Binary: Substitute every hex character with its 4-bit binary nibble. For example, 0x2D: 2 = 0010, D (13) = 1101 → 00101101 (or 101101).
Binary to Decimal: Multiply each bit by its positional power of 2 starting from position 0 on the right. For 101101: $(1 \times 32) + (0 \times 16) + (1 \times 8) + (1 \times 4) + (0 \times 2) + (1 \times 1) = 32 + 8 + 4 + 1 = 45$.
Decimal to Hexadecimal: Repeatedly divide the decimal integer by 16 and record the integer remainders. Read remainders from bottom to top.
Binary to Octal: Group bits into clusters of 3 starting from the right (pad with leading zeros if needed). Each 3-bit chunk converts into a single octal digit (e.g., 101 101 → 55 in octal = 45 in decimal).
4. Standard Programming Prefixes
0bor0B: Identifies Binary literals in JavaScript, Python, C++, Rust, and Go (e.g.,0b101101).0oor0O: Identifies Octal literals (e.g.,0o77).0xor0X: Identifies Hexadecimal literals across almost all modern programming languages (e.g.,0x2D,0xFF).