Understanding Radix or Number Base
In the world of computing and mathematics, the concept of radix (or number base) is fundamental. It defines how numbers are represented and manipulated in different numeral systems. Whether you're working with binary, octal, decimal, or hexadecimal, understanding radix and how to convert between bases is essential.
What is Radix?
The radix (or base) of a number system is the number of unique digits, including zero, used to represent numbers in that system. For example:
- Binary (Base 2): Uses digits
0
and1
. - Octal (Base 8): Uses digits
0
through7
. - Decimal (Base 10): Uses digits
0
through9
. - Hexadecimal (Base 16): Uses digits
0
through9
and lettersA
throughF
.
Why is Radix Important?
Different number bases are used in various computing contexts:
- Binary (Base 2): Used internally by computers because it aligns with the on/off states of transistors.
- Hexadecimal (Base 16): Used in programming and debugging because it provides a compact representation of binary data.
- Decimal (Base 10): Used in everyday life and most human-readable calculations.
Mathematical Representation of Radix
In a positional numeral system, the value of a number is determined by the sum of each digit multiplied by the radix raised to the power of its position index (starting from 0 on the right). Mathematically, this can be expressed as:
Number = dn × rn + dn-1 × rn-1 + ... + d0 × r0
Where:
di
is the digit at positioni
.r
is the radix (base).n
is the position index of the digit.
Example: Decimal to Binary Conversion
Let's convert the decimal number 13
to binary (base 2):
Step 1: Divide the number by 2 and record the remainder.
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Step 2: Read the remainders in reverse order.
Binary representation: 1101
Example: Binary to Decimal Conversion
Let's convert the binary number 1101
to decimal (base 10):
Step 1: Multiply each digit by 2 raised to its position index (starting from 0 on the right).
1 × 23 = 8
1 × 22 = 4
0 × 21 = 0
1 × 20 = 1
Step 2: Sum the results.
8 + 4 + 0 + 1 = 13
Decimal representation: 13
General Algorithm for Base Conversion
To convert a number from one base to another, follow these steps:
- Convert from the original base to decimal:
- Multiply each digit by the original base raised to the power of its position index.
- Sum the results to get the decimal value.
- Convert from decimal to the target base:
- Divide the decimal number by the target base and record the remainder.
- Repeat the process with the quotient until it becomes zero.
- The target base number is the sequence of remainders read in reverse order.
Practical Example: Hexadecimal to Binary
Let's convert the hexadecimal number 1F
to binary:
Step 1: Convert hexadecimal to decimal.
1 × 161 = 16
F (15) × 160 = 15
Decimal value: 16 + 15 = 31
Step 2: Convert decimal to binary.
31 ÷ 2 = 15 remainder 1
15 ÷ 2 = 7 remainder 1
7 ÷ 2 = 3 remainder 1
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Binary representation: 11111
Direct Conversion Between Bases
When converting between bases that are powers of the same number (e.g., binary and hexadecimal or binary and octal), you can use direct conversion. This method is faster and more efficient than converting through an intermediate base like decimal.
Binary to Hexadecimal (Direct Conversion)
Since ( 16 = 2^4 ), each hexadecimal digit corresponds to exactly 4 binary digits. The algorithm is as follows:
- Group Binary Digits: Starting from the right, group the binary digits into sets of 4. Add leading zeros if necessary to make the last group complete.
- Map Each Group to Hexadecimal: Convert each 4-digit binary group to its corresponding hexadecimal digit using the mapping table below.
Binary-to-Hexadecimal Mapping Table
| Binary | Hexadecimal |
|--------|-------------|
| 0000 | 0 |
| 0001 | 1 |
| 0010 | 2 |
| 0011 | 3 |
| 0100 | 4 |
| 0101 | 5 |
| 0110 | 6 |
| 0111 | 7 |
| 1000 | 8 |
| 1001 | 9 |
| 1010 | A |
| 1011 | B |
| 1100 | C |
| 1101 | D |
| 1110 | E |
| 1111 | F |
Example
Convert the binary number 110101110
to hexadecimal.
Step 1: Group Binary Digits
Original Binary: 1 1 0 1 0 1 1 1 0
Grouped (4 digits): 0001 1010 1110
Step 2: Map Each Group to Hexadecimal
0001 → 1
1010 → A
1110 → E
Result: 1AE
Hexadecimal to Binary (Direct Conversion)
To convert from hexadecimal to binary, reverse the process:
- Map Each Hexadecimal Digit to Binary: Convert each hexadecimal digit to its 4-digit binary equivalent using the mapping table above.
- Combine Binary Digits: Concatenate the binary digits to form the final binary number.
Example
Convert the hexadecimal number 2F5
to binary.
Step 1: Map Each Hexadecimal Digit to Binary
2 → 0010
F → 1111
5 → 0101
Step 2: Combine Binary Digits
0010 1111 0101
Result: 001011110101 (or 1011110101 after removing leading zeros)
Binary to Octal (Direct Conversion)
Since ( 8 = 2^3 ), each octal digit corresponds to exactly 3 binary digits. The algorithm is as follows:
- Group Binary Digits: Starting from the right, group the binary digits into sets of 3. Add leading zeros if necessary to make the last group complete.
- Map Each Group to Octal: Convert each 3-digit binary group to its corresponding octal digit using the mapping table below.
Binary-to-Octal Mapping Table
| Binary | Octal |
|--------|-------|
| 000 | 0 |
| 001 | 1 |
| 010 | 2 |
| 011 | 3 |
| 100 | 4 |
| 101 | 5 |
| 110 | 6 |
| 111 | 7 |
Example
Convert the binary number 1011101
to octal.
Step 1: Group Binary Digits
Original Binary: 1 0 1 1 1 0 1
Grouped (3 digits): 001 011 101
Step 2: Map Each Group to Octal
001 → 1
011 → 3
101 → 5
Result: 135
Octal to Binary (Direct Conversion)
To convert from octal to binary, reverse the process:
- Map Each Octal Digit to Binary: Convert each octal digit to its 3-digit binary equivalent using the mapping table above.
- Combine Binary Digits: Concatenate the binary digits to form the final binary number.
Example
Convert the octal number 347
to binary.
Step 1: Map Each Octal Digit to Binary
3 → 011
4 → 100
7 → 111
Step 2: Combine Binary Digits
011 100 111
Result: 011100111 (or 11100111 after removing leading zeros)
Conclusion
Understanding radix and number base conversion is crucial for working with different numeral systems in computing and mathematics. By mastering the mathematical principles behind base conversion, you can easily translate numbers between binary, octal, decimal, and hexadecimal systems. Whether you're debugging code, designing hardware, or simply exploring number theory, this knowledge is invaluable.