7.1 Radix Number Systems & Inter-Base Conversion
π‘ Core Intuition: The Odometer & The Radix Weight Balanceβ
Every number we write is a shorthand code. When you write the number , you do not simply possess three digits; you possess:
The baseβor Radix ()βdefines how many distinct numerical symbols exist in that system before a column rolls over to zero and propagates a carry to the next position, exactly like the mechanical wheels of an automotive odometer.
π³ The Everyday Analogy: The Currency Exchange Deskβ
Imagine an eccentric bank where cash is dispensed strictly in powers of a currency unit:
- In a Decimal (Base-10) bank, the teller dispenses
$1000,$100,$10, and$1notes. - In a Binary (Base-2) bank, the teller only stocks
$16,$8,$4,$2, and$1notes. - In an Octal (Base-8) bank, the teller dispenses
$64,$8, and$1notes. - In a Hexadecimal (Base-16) bank, the teller dispenses
$4096,$256,$16, and$1notes.
If you request $42 from the Binary teller, they hand you:
Each base is merely a different combination of power weights describing the exact same underlying physical quantity!
π» Bridging to Computer Science & Silicon Hardwareβ
Why do digital computers operate in binary when humans think in decimal?
- CMOS Voltage Margins: In silicon, distinguishing between two discrete electrical voltage states (ground and supply ) provides maximum noise immunity. Distinguishing 10 distinct voltage levels ( per state) would cause catastrophic bit flips from thermal noise.
- Octal () and Hexadecimal () as Human Shorthand: Modern 64-bit microprocessors deal with memory addresses like
0x7FFE_4A10_B9C0. Writing this address in binary requires 64 ones and zeros (0111111111111110...), which is humanly impossible to parse without error. Because , each hexadecimal character directly groups exactly 4 binary bits (one nibble), providing a 1:1 lossless window into physical hardware memory without performing complex division.
πTable of Contents
- π Positional Number Systems & The Radix Polynomial
- ποΈ Standard Radices in Computing (Base 2, 8, 10, 16)
- π Non-Decimal to Decimal: Weighted Expansion
- β Decimal to Any Base: Successive Division & Multiplication
- β‘ Power-of-Two Fast Groupings (Binary β Octal β Hex)
- π Arbitrary Base-to-Base Conversions (The Decimal Bridge)
- ποΈ Interactive Radix Converter & Derivation Stepper
- β οΈ Fractional Precision Limits & Floating-Point Hazards
- π Real-World Production Context: Memory Addressing, Endianness & Unix Permissions
- π Numerical Applications & Worked Examples
- π― Exam & Interview Pitfall Check
π Positional Number Systems & The Radix Polynomialβ
In a positional number system with radix , any real number is expressed as an ordered sequence of digits:
Where:
- is the Radix (Base) of the number system ().
- is a digit satisfying .
- is the number of integer digits to the left of the radix point.
- is the number of fractional digits to the right of the radix point.
Each position corresponds to an exponential weight . Notice that:
- is always the units digit directly preceding the radix point.
- Positions to the left increment powers:
- Positions to the right decrement negative powers:
ποΈ Standard Radices in Computing (Base 2, 8, 10, 16)β
π Non-Decimal to Decimal: Weighted Expansionβ
To convert any number from an arbitrary base to Decimal (Base-10), expand every digit into its corresponding weight and compute the arithmetic sum in decimal.
Example 1: Binary to Decimal with Fractionsβ
Convert to decimal:
Example 2: Hexadecimal to Decimalβ
Convert to decimal (recall ):
β Decimal to Any Base: Successive Division & Multiplicationβ
Converting from Decimal (Base-10) to an arbitrary target radix requires separating the number into its integer and fractional components:
- Integer Part: Processed using Successive Division by .
- Fractional Part: Processed using Successive Multiplication by .
Decimal to Arbitrary Radix (Base r) Conversion Framework
Decomposing real numbers into integer division and fractional multiplication pipelines
Integer Part (N_int)
- β’Divide integer dividend N by target radix r at each iteration.
- β’Record remainder as the current radix-r digit (range: 0 to r - 1).
- β’Replace dividend with the integer quotient: Q = βN / rβ.
- β’Termination Condition: Stop when quotient reaches 0.
- β’Crucial Read Order: Read remainders Bottom-to-Top (First remainder = LSB, Final remainder = MSB).
Fractional Part (N_frac)
- β’Multiply current fractional part by target radix r at each iteration.
- β’Extract the generated integer carry digit (range: 0 to r - 1).
- β’Retain the remaining purely fractional part for the next cycle.
- β’Termination Condition: Stop when fraction equals 0 or required precision bits are met.
- β’Crucial Read Order: Read extracted integer digits Top-to-Bottom (First carry = MSB / rβ»ΒΉ, subsequent = rβ»Β², rβ»Β³, ...).
Dual-Pipeline Base Conversion Execution Flow
Step-by-step algorithm branching into Integer Division and Fractional Multiplication
Divide by Target Radix r
Perform integer division of dividend N by radix r.
Record Remainder (R)
Remainder R becomes next digit. First remainder is LSB.
Check Q = 0 Condition
If Q > 0, repeat division. When Q = 0, stop.
Read Bottom-to-Top
Assemble integer digits in reverse generation order (Bottom-to-Top).
Multiply by Radix r
Multiply remaining fractional value by target radix r.
Record Integer Carry
Extracted integer is next fractional digit. First carry is MSB (rβ»ΒΉ).
Check F = 0 Condition
Continue multiplying remaining fraction until it reaches 0 or required precision.
Read Top-to-Bottom
Assemble fractional digits in direct order of extraction (Top-to-Bottom).
1. Integer Conversion: Successive Division Algorithmβ
Divide the integer repeatedly by target base . At each iteration:
- The remainder becomes the next digit.
- The quotient becomes the dividend for the next step.
- Stop when the quotient reaches .
- Critical Order: The first remainder generated is the Least Significant Bit (LSB) (). The last remainder generated is the Most Significant Bit (MSB). Read from Bottom to Top!
Example: Convert to Binary ()β
Reading bottom-to-top: .
2. Fractional Conversion: Successive Multiplication Algorithmβ
Multiply the fractional portion repeatedly by target base . At each iteration:
- The integer part of the product is extracted as the next digit.
- The remaining fractional part is multiplied again by .
- Stop when the fractional part reaches exactly , or when desired precision is reached.
- Critical Order: The first integer extracted corresponds to (the MSB of the fraction). The subsequent integers follow downwards. Read from Top to Bottom!
Example: Convert to Binary ()β
Reading top-to-bottom: .
β‘ Power-of-Two Fast Groupings (Binary β Octal β Hex)β
Whenever two radices are related by a power of two (), conversion bypasses decimal arithmetic completely!
Binary Hexadecimal Fast Mappingβ
- Binary to Hexadecimal: Group the binary string into sets of 4 bits, starting from the radix point:
- For the integer part: Group moving left from the radix point (pad leading zeros on the far left if needed).
- For the fractional part: Group moving right from the radix point (pad trailing zeros on the far right if needed).
- Substitute each 4-bit group with its hexadecimal symbol ().
Example: Convert to Hexadecimalβ
- Integer part: (padded with leading zero)
- Fractional part: (padded with two trailing zeros)
- Result:
| Binary Groups | 0101 | 1110 | 1011 | . | 1011 | 0100 |
|---|---|---|---|---|---|---|
| Hex Equivalent | 5 | E | B | . | B | 4 |
Binary Octal Fast Mappingβ
Group into clusters of 3 bits:
π Arbitrary Base-to-Base Conversions (The Decimal Bridge)β
When converting between two arbitrary bases where neither is an integer power of the other (e.g., Base-5 to Base-7, or Base-3 to Base-8), use Decimal as the intermediate bridge:
Concrete Problem: Convert to Base 7β
Step 1: Convert Base-5 to Decimal
Step 2: Convert to Base-7
- Integer (73):
- Fraction (0.4):
Final Result: .
ποΈ Interactive Radix Converter & Derivation Stepperβ
Experiment with any integer or fractional value across Binary, Octal, Decimal, and Hexadecimal. Inspect the full successive division and multiplication tables live:
| Dividend | Divisor | Quotient | Remainder |
|---|---|---|---|
| 42 | Γ· 2 | 21 | 0 |
| 21 | Γ· 2 | 10 | 1 |
| 10 | Γ· 2 | 5 | 0 |
| 5 | Γ· 2 | 2 | 1 |
| 2 | Γ· 2 | 1 | 0 |
| 1 | Γ· 2 | 0 | 1 |
| Fraction | Multiplier | Product | Integer Part |
|---|---|---|---|
| 0.625000 | Γ 2 | 1.250000 | 1 |
| 0.250000 | Γ 2 | 0.500000 | 0 |
| 0.500000 | Γ 2 | 1.000000 | 1 |
β οΈ Fractional Precision Limits & Floating-Point Hazardsβ
One of the most profound realizations in computer systems is that finite decimal fractions do not necessarily terminate in binary!
Consider the seemingly innocuous decimal number (one-tenth):
Because silicon registers have finite bit width (32-bit single precision or 64-bit double precision), the repeating bits must eventually be truncated or rounded! This leads to the famous programming anomaly:
console.log(0.1 + 0.2 === 0.3); // Output: FALSE! (Evaluates to 0.30000000000000004)
A reduced fraction terminates in radix if and only if all prime factors of the denominator divide the radix .
- In Decimal (): Any fraction whose denominator factors into only s and s terminates (e.g. ).
- In Binary (): Only fractions whose denominator is an exact power of () terminate! contains a prime factor , making it infinitely repeating in binary!
π Real-World Production Context: Memory Addressing, Endianness & Unix Permissionsβ
In system programming and computer architecture, multi-radix mastery directly bridges software abstraction with underlying hardware registers.
Computing Systems Multi-Radix Representation Hierarchy
POSIX File Permissions & Hex Bitmasks
Developers use octal chmod 755 (rwxr-xr-x) and hexadecimal color hexes (#FF5733) or network socket flags for readability.
64-Bit Virtual Memory Addressing (Hex)
Page tables and GDB debuggers express 64-bit pointers in 16 hex digits (e.g. 0x7FFF_FFFF_E000), where each character groups exactly 4 binary bits.
ALU Register Files & Floating-Point Units
ALU datapaths execute operations on 32-bit/64-bit binary registers, where fractions like 0.1 become infinitely repeating mantissas.
CMOS Dual Voltage Levels (0V / 1.2V)
Transistors switch between GND (Logic 0) and VDD (Logic 1), providing maximal noise margin in binary logic.
- Memory Addressing in Hexadecimal: Modern 64-bit systems handle addresses that would be unreadable in binary. Because , each hexadecimal character directly corresponds to 4 physical flip-flop states (one nibble), enabling engineers to audit memory layouts losslessly without division.
- Octal in Unix Permissions: The classic POSIX permissions model maps 3 bits (Read , Write , Execute ) into a single octal digit ( through ). An octal string like
755provides an instant view of three independent 3-bit registers controlling Owner, Group, and Other privileges.
π Numerical Applications & Worked Examplesβ
Example 1: High-Precision Fractional Conversion to Binary & Hexadecimalβ
Problem Statement:
Convert the decimal quantity into:
- Exact binary representation.
- Hexadecimal representation via power-of-two nibble grouping.
Step-by-Step Solution:
- Integer Conversion ( Binary via Successive Division by 2):
- rem (LSB)
- rem
- rem
- rem
- rem
- rem
- rem (MSB)
- Reading Bottom-to-Top: .
- Fractional Conversion ( Binary via Successive Multiplication by 2):
- (MSB, )
- ()
- ()
- ()
- Fraction terminates at 0. Reading Top-to-Bottom: .
- Combined Binary Result: .
- Hexadecimal Conversion via 4-Bit Nibble Grouping:
- Pad integer on the left to complete 4-bit nibbles: .
- Fractional nibble: .
- Final Hexadecimal Result: .
Example 2: Arbitrary Base Conversion via the Decimal Bridgeβ
Problem Statement:
Convert the base-5 number into its equivalent octal (base-8) representation, carrying the fractional conversion to 3 octal places.
Step-by-Step Solution:
- Bridge to Decimal via Radix-5 Polynomial Expansion:
- Convert Decimal Integer to Octal via Successive Division by 8:
- rem (LSB)
- rem
- rem (MSB)
- Reading Bottom-to-Top: .
- Convert Decimal Fraction to Octal via Successive Multiplication by 8:
- (First octal fractional digit)
- Fractional Part: .
- Final Result: .
Example 3: Determination of Unknown Radix from an Algebraic Equationβ
Problem Statement:
Find the unknown radix for which the arithmetic equation is valid:
Step-by-Step Solution:
- Identify Positional Constraints on Radix :
- The equation contains the digit in and digit in .
- Because every digit in radix must be , the base must satisfy (i.e. ).
- Expand Both Sides into Decimal Algebraic Expressions:
- LHS:
- RHS:
- Solve for :
Square both sides:
- Verification:
- Check : .
- .
- The constraint is met exactly. The radix is .
π― Exam & Interview Pitfall Checkβ
- Why must we pad zeros on the LEFT for integers and on the RIGHT for fractions when grouping into nibbles?
Prepending zeros to an integer () does not change its numerical magnitude (). Similarly, appending zeros to the tail of a fraction () does not change its value. However, appending zeros to an integer or prepending zeros to a fraction radically shifts the radix power weights and corrupts the number! - How many total binary bits are required to store an -digit decimal integer?
To represent an integer , we need . Thus, each decimal digit requires approximately bits (practically, we allocate 4 bits per decimal digit in BCD).
- Trap: Forgetting that a Hexadecimal digit can represent up to 15, not 16.
In Base-16, the symbol10represents . The digit for decimal 15 isF. Never write16or10as a single digit in base 16! - Trap: Inverting the read-out order between division and multiplication.
- Division remainders (integer conversion) are read Bottom to Top (first remainder is LSB).
- Multiplication products (fractional conversion) are read Top to Bottom (first extracted digit is MSB). Inverting this order is the most common error in timed university examinations!