Deep Dive into Number Systems
⚡ Foundations of Digital Computing: At the physical layer, all modern computers operate using voltage differentials representing Binary (
0and1). To make massive strings of binary digits human-readable and mathematically ergonomic, computer scientists use Octal (Base-8) and Hexadecimal (Base-16). Mastering radix conversions, bit grouping, and positional weights is the cornerstone of systems engineering, memory debugging, and low-level optimization.
1. Positional Number Systems & The Power of Radix
A positional number system expresses any real number as a sum of digits multiplied by powers of the system’s base (radix)b:
Value = (d_n-1 * b^(n-1)) + ... + (d_1 * b^1) + (d_0 * b^0) + (d_-1 * b^-1) + ... +-----------------------------------------------------------------------------------+
| FOUR FOUNDATIONAL NUMBER SYSTEMS |
+-----------------------------------------------------------------------------------+
1. Binary (Base-2): Digits: {0, 1}
Prefix: 0b (e.g. 0b10110110)
Purpose: Native hardware voltage states (Transistors)
2. Octal (Base-8): Digits: {0, 1, 2, 3, 4, 5, 6, 7}
Prefix: 0o (e.g. 0o755)
Purpose: 3-bit grouping; Unix file permissions, legacy I/O
3. Decimal (Base-10): Digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}
Purpose: Human everyday mathematics
4. Hexadecimal (Base-16): Digits: {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F}
Prefix: 0x (e.g. 0xDEADBEEF)
Purpose: 4-bit nibble grouping; Memory addresses, RGB colors
+-----------------------------------------------------------------------------------+2. Master Conversion Table (Values 0 to 15)
Every hexadecimal digit maps to exactly 4 binary bits (a nibble), and every octal digit maps to 3 binary bits:
Decimal (10) | Binary (2) | Octal (8) | Hex (16) | Nibble Decomposition (2³, 2², 2¹, 2⁰) |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0 | 0 + 0 + 0 + 0 |
| 1 | 0001 | 1 | 1 | 0 + 0 + 0 + 1 |
| 2 | 0010 | 2 | 2 | 0 + 0 + 2 + 0 |
| 3 | 0011 | 3 | 3 | 0 + 0 + 2 + 1 |
| 4 | 0100 | 4 | 4 | 0 + 4 + 0 + 0 |
| 5 | 0101 | 5 | 5 | 0 + 4 + 0 + 1 |
| 6 | 0110 | 6 | 6 | 0 + 4 + 2 + 0 |
| 7 | 0111 | 7 | 7 | 0 + 4 + 2 + 1 |
| 8 | 1000 | 10 | 8 | 8 + 0 + 0 + 0 |
| 9 | 1001 | 11 | 9 | 8 + 0 + 0 + 1 |
| 10 | 1010 | 12 | A | 8 + 0 + 2 + 0 |
| 11 | 1011 | 13 | B | 8 + 0 + 2 + 1 |
| 12 | 1100 | 14 | C | 8 + 4 + 0 + 0 |
| 13 | 1101 | 15 | D | 8 + 4 + 0 + 1 |
| 14 | 1110 | 16 | E | 8 + 4 + 2 + 0 |
| 15 | 1111 | 17 | F | 8 + 4 + 2 + 1 |
3. Step-by-Step Conversion Algorithms
┌──────────────────────┐
│ Decimal (10) │
└──────────────────────┘
▲ │
Positional Expansion │ │ Successive Division (Radix)
│ ▼
┌───────────────┐ ┌──────────────────────┐ ┌───────────────────┐
│ Octal (8) │ ◄── │ Binary (2) │ ──► │ Hexadecimal (16) │
└───────────────┘ └──────────────────────┘ └───────────────────┘
3-Bit Grouping 4-Bit Grouping (Nibbles) 3.1 Decimal to Binary, Octal, and Hexadecimal (Successive Division)
To convert a decimal integer to any base b:
- Divide the number by the target base
b. - Record the remainder.
- Repeat with the integer quotient until the quotient reaches
0. - Read the remainders from bottom to top (Last Remainder = Most Significant Digit).
Example: Convert Decimal 157 to Binary, Octal, and Hexadecimal
Decimal to Binary (Base 2):
157 / 2 = 78 (Remainder 1)↑ LSB78 / 2 = 39 (Remainder 0)39 / 2 = 19 (Remainder 1)19 / 2 = 9 (Remainder 1)9 / 2 = 4 (Remainder 1)4 / 2 = 2 (Remainder 0)2 / 2 = 1 (Remainder 0)1 / 2 = 0 (Remainder 1)↑ MSB- Result:
157₁₀ = 10011101₂
-
Decimal to Octal (Base 8):
157 / 8 = 19 (Remainder 5)19 / 8 = 2 (Remainder 3)2 / 8 = 0 (Remainder 2)- Result:
157₁₀ = 235₈
-
Decimal to Hexadecimal (Base 16):
157 / 16 = 9 (Remainder 13 -> D)9 / 16 = 0 (Remainder 9)- Result:
157₁₀ = 0x9D
3.2 Binary to Hexadecimal & Hexadecimal to Binary (The 4-Bit Rule)
Because 2⁴ = 16, every hexadecimal digit corresponds exactly to a 4-bit nibble. This allows instant conversion without arithmetic division:
Example: Convert Binary 1101011010111100 to Hexadecimal
- Partition the bits into groups of 4 starting from the right (LSB):
[ 1101 ] [ 0110 ] [ 1011 ] [ 1100 ] - Replace each 4-bit group with its single hexadecimal character:
1101₂ = 8 + 4 + 0 + 1 = 13 = D0110₂ = 0 + 4 + 2 + 0 = 6 = 61011₂ = 8 + 0 + 2 + 1 = 11 = B1100₂ = 8 + 4 + 0 + 0 = 12 = C
- Result:
0b1101011010111100 = 0xD6BC
Example: Convert Hexadecimal 0x3FA9 to Binary
Expand each hex character into its 4-bit binary representation:
3 -> 0011F -> 1111A -> 10109 -> 1001- Result:
0b0011_1111_1010_1001
3.3 Binary to Octal & Octal to Binary (The 3-Bit Rule)
Because 2³ = 8, every octal digit corresponds exactly to 3 binary bits:
Example: Convert Binary 110101101 to Octal
- Partition into groups of 3 from the right:
[ 110 ] [ 101 ] [ 101 ] - Convert each group:
110₂ = 4 + 2 + 0 = 6101₂ = 4 + 0 + 1 = 5101₂ = 4 + 0 + 1 = 5
- Result:
655₈
3.4 Octal to Hexadecimal Conversion (Via Binary Pivot)
To convert between Octal and Hexadecimal directly, use Binary as the intermediate pivot:
Octal 754₈ --> [111] [101] [100] --> [0001] [1110] [1100] --> 0x1EC 4. Real-World Engineering Applications
4.1 Unix File Permissions (Octal in Action)
In Unix/Linux systems, file permissions are divided into 3 security tiers: User (u), Group (g), and Others (o). Each tier has 3 bits: Read (r=4), Write (w=2), and Execute (x=1):
+-----------------------------------------------------------------------+
| UNIX PERMISSION OCTAL DECOMPOSITION |
+-----------------------------------------------------------------------+
Permission: r w x r - x r - x (chmod 755)
Binary: 1 1 1 1 0 1 1 0 1
Values: 4+2+1 4+0+1 4+0+1
Octal: 7 5 5
+-----------------------------------------------------------------------+ 4.2 Web Color Codes (Hexadecimal RGB)
CSS 24-bit TrueColor values represent Red, Green, and Blue channels (0–255 each) packed into 3 bytes (6 hex characters):
#2563EB --> Red: 0x25 (37), Green: 0x63 (99), Blue: 0xEB (235) 4.3 Memory Pointers & Crash Dumps
Hexadecimal is the standard for memory addresses because a 64-bit memory pointer fits into 16 clean hex characters: 0x00007FFEFA89BC10
5. Summary & Rapid Conversion Cheat Sheet
+───────────────────────────────────────────────────────────────────────+
| RAPID CHUNK GROUPING CHEAT SHEET |
+───────────────────────────────────────────────────────────────────────+
Hex to Binary: Each character ──> 4 Bits (e.g. 0xA ──> 1010)
Binary to Hex: Group from right by 4 Bits ──> Single Hex Digit
Oct to Binary: Each character ──> 3 Bits (e.g. 0o7 ──> 111)
Binary to Oct: Group from right by 3 Bits ──> Single Octal Digit
+───────────────────────────────────────────────────────────────────────+ | Operation | Strategy | Example |
|---|---|---|
| Decimal ➔ Base N | Repeated division by N; collect remainders upwards. | 255 / 16 ==> 0xFF |
| Base N ➔ Decimal | Multiply each digit by N^(position) and sum. | 1101₂ = 1(8) + 1(4) + 0(2) + 1(1) = 13 |
| Binary ➔ Hex | Group bits by 4 from right to left. | 1111 0000 ==> 0xF0 |
| Binary ➔ Octal | Group bits by 3 from right to left. | 111 000 ==> 70₈ |
Positional number systems provide the bridge between physical silicon transistors and human software architecture.
Comments & Discussion