Radix and Radix Conversion
CREATED: 2026 / 05 / 07 Thu
UPDATED: 2026 / 05 / 07 Thu
What Is a Radix?
A radix (or base) is the number that appears in “binary”, “octal”, “decimal”, and “hexadecimal” — the number itself. The decimal system we use every day works with 10 kinds of digits (0–9), so its radix is 10.
While less natural for humans, binary (base-2), octal (base-8), and hexadecimal (base-16) are all commonly used in computing.
| System | Radix | Digits / Symbols |
|---|---|---|
| Binary | 2 | 0, 1 |
| Octal | 8 | 0–7 |
| Decimal | 10 | 0–9 |
| Hexadecimal | 16 | 0–9, A(10), B(11), C(12), D(13), E(14), F(15) |
Binary, Octal, and Hexadecimal
Binary
Binary uses only 0 and 1. Each position to the left doubles in value.
| Decimal | Binary |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| 3 | 0011 |
| 4 | 0100 |
| 5 | 0101 |
| 6 | 0110 |
| 7 | 0111 |
| 8 | 1000 |
Binary literals are often written with a 0b prefix or a (2) suffix (e.g., 0b1010, 1010(2)).
Octal
Octal uses digits 0–7. Because exactly 3 bits map to one octal digit, converting between binary and octal is straightforward.
| Decimal | Octal |
|---|---|
| 0 | 0 |
| 7 | 7 |
| 8 | 10 |
| 15 | 17 |
| 16 | 20 |
| 63 | 77 |
| 64 | 100 |
Octal literals are often written with a 0 or 0o prefix (e.g., 017, 0o17).
Hexadecimal
Hexadecimal uses digits 0–9 and letters A–F. Because exactly 4 bits map to one hex digit, one byte (8 bits) is neatly expressed as two hex digits.
| Decimal | Hex |
|---|---|
| 0 | 0 |
| 9 | 9 |
| 10 | A |
| 15 | F |
| 16 | 10 |
| 255 | FF |
| 256 | 100 |
Hex literals are often written with a 0x or 0X prefix (e.g., 0xFF, 0x1A).
Converting from Base-n to Decimal
Sum each digit multiplied by the radix raised to its position. The rightmost digit of the integer part is position 0.
Sum of: (digit value) × n^(position)
Binary → Decimal Example
Convert 1101(2) to decimal.
1 × 2^3 + 1 × 2^2 + 0 × 2^1 + 1 × 2^0
= 8 + 4 + 0 + 1
= 13
When a number has a fractional part, the first digit after the binary point is position -1, the next is -2, and so on.
Convert 1101.011(2) to decimal.
1 × 2^3 + 1 × 2^2 + 0 × 2^1 + 1 × 2^0 + 0 × 2^-1 + 1 × 2^-2 + 1 × 2^-3
= 8 + 4 + 0 + 1 + 0 + 0.25 + 0.125
= 13.375
Octal → Decimal Example
Convert 145(8) to decimal.
1 × 8^2 + 4 × 8^1 + 5 × 8^0
= 64 + 32 + 5
= 101
Hexadecimal → Decimal Example
Convert 2F(16) to decimal.
2 × 16^1 + 15 × 16^0
= 32 + 15
= 47
Converting from Decimal to Base-n
Repeatedly divide by the radix until the quotient reaches 0, then read the remainders in reverse order.
Decimal → Binary Example
Convert 13 to binary.
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Remainders in reverse: 1101(2)
Decimal → Octal Example
Convert 101 to octal.
101 ÷ 8 = 12 remainder 5
12 ÷ 8 = 1 remainder 4
1 ÷ 8 = 0 remainder 1
Remainders in reverse: 145(8)
Decimal → Hexadecimal Example
Convert 47 to hexadecimal.
47 ÷ 16 = 2 remainder 15 (F)
2 ÷ 16 = 0 remainder 2
Remainders in reverse: 2F(16)
Converting between Arbitrary Bases
Via Decimal
The simplest approach is to convert through decimal in two steps.
base-n → decimal → base-m
For example, to convert 1101(2) to octal:
1101(2) → 13(10) → 15(8)
This alone is usually fine in practice, but it’s useful to also know the direct methods below.
Binary ↔ Octal (3-bit grouping)
Three binary digits correspond exactly to one octal digit. Group the bits in sets of three from the right, then convert each group.
Convert 101110(2) to octal:
101 110
5 6
= 56(8)
To convert 56(8) back to binary, expand each octal digit into three binary digits:
5 → 101
6 → 110
= 101110(2)
Binary ↔ Hexadecimal (4-bit grouping)
Four binary digits correspond exactly to one hexadecimal digit. Group the bits in sets of four from the right, then convert each group.
Convert 10111110(2) to hexadecimal:
1011 1110
B E
= BE(16)
To convert BE(16) back to binary, expand each hex digit into four binary digits:
B(11) → 1011
E(14) → 1110
= 10111110(2)
Arithmetic
In practice, it’s perfectly fine to convert to decimal, calculate, and convert back. That said, here is how arithmetic works in each base.
Addition
Binary addition works just like decimal: carry when the sum reaches the radix (2).
Carry rules:
0 + 0 = 0
0 + 1 = 1
1 + 0 = 1
1 + 1 = 10 (write 0, carry 1)
Example: 0101(2) + 0011(2)
0 1 0 1
+ 0 0 1 1
---------
1 0 0 0
Carries propagate through positions 1, 2, and 3, setting position 4 to 1, giving 1000(2).
Verification in decimal: 5 + 3 = 8 = 1000(2).
The same principle applies to octal and hexadecimal, carrying when the digit sum reaches 8 or 16 respectively.
Octal Example
15(8) + 07(8)
Position 1: 5 + 7 = 12 → 12 ≥ 8, write 4 and carry 1
Position 2: 1 + 0 + 1 (carry) = 2
1 5
+ 0 7
-----
2 4
Verification: 13 + 7 = 20 = 24(8).
Hexadecimal Example
1A(16) + 2F(16)
Position 1: A(10) + F(15) = 25 → 25 ≥ 16, write 9 and carry 1
Position 2: 1 + 2 + 1 (carry) = 4
1 A
+ 2 F
-----
4 9
Verification: 26 + 47 = 73 = 49(16).
Subtraction
When a digit cannot be subtracted, borrow from the next higher position (adding the radix to the current position).
Example: 1000(2) - 0011(2)
1 0 0 0
- 0 0 1 1
---------
0 1 0 1
1000(2) has 0 in positions 1, 2, and 3, so we must borrow from the top.
Passing the borrow down the chain gives each position a value to work with:
- Position 1:
10(2)−1(2)=1(2) - Position 2:
1(2)−1(2)=0(2) - Position 3:
1(2)−0(2)=1(2) - Position 4: borrowed away, so
0(2)−0(2)=0(2)
Verification: 8 − 3 = 5 = 0101(2).
Octal Example
24(8) - 07(8)
Position 1: 4 - 7 → borrow 8 from position 2 → (4 + 8) - 7 = 5
Position 2: 2 - 1 (borrowed) - 0 = 1
2 4
- 0 7
-----
1 5
Verification: 20 − 7 = 13 = 15(8).
Hexadecimal Example
49(16) - 2F(16)
Position 1: 9 - F(15) → borrow 16 → (9 + 16) - 15 = 10 (A)
Position 2: 4 - 1 (borrowed) - 2 = 1
4 9
- 2 F
-----
1 A
Verification: 73 − 47 = 26 = 1A(16).
Multiplication
Binary multiplication is performed like decimal long multiplication: multiply each digit of the lower number by the upper number, shift by its position, then sum the partial products.
Example: 0101(2) × 0011(2)
0 1 0 1 (= 5)
× 0 0 1 1 (= 3)
-------------
0 1 0 1 (0101 × 1, shift 0)
0 1 0 1 (0101 × 1, shift 1)
0 0 0 0
0 0 0 0
-------------
0 0 0 1 1 1 1 (= 15)
For each bit of the lower number (from position 1 up), take the AND with the upper number, shift by that position, and sum the results.
Octal Example
15(8) × 3(8)
Position 1: 5 × 3 = 15 → 15 ≥ 8, write 7 and carry 1 (15 = 8 + 7)
Position 2: 1 × 3 = 3, plus carry 1 = 4
1 5
× 3
-----
4 7
Verification: 13 × 3 = 39 = 47(8).
Hexadecimal Example
1A(16) × 3(16)
Position 1: A(10) × 3 = 30 → 30 ≥ 16, write E(14) and carry 1 (30 = 16 + 14)
Position 2: 1 × 3 = 3, plus carry 1 = 4
1 A
× 3
-----
4 E
Verification: 26 × 3 = 78 = 4E(16).
Division
Binary division works just like decimal long division.
1111(2) ÷ 11(2)
1 0 1
-------
1 1 ) 1 1 1 1
1 1
-------
0 1
0
---
1 1
1 1
---
0
Verification: 15 ÷ 3 = 5 = 101(2).
Octal Example
47(8) ÷ 3(8)
1 5
---
3 ) 4 7
3 (3 × 1 = 3)
---
1 7
1 7 (3 × 5 = 17(8))
---
0
Verification: 39 ÷ 3 = 13 = 15(8).
Hexadecimal Example
4E(16) ÷ 3(16)
1 A
---
3 ) 4 E
3 (3 × 1 = 3)
---
1 E
1 E (3 × A(10) = 30 = 1E(16))
---
0
Verification: 78 ÷ 3 = 26 = 1A(16).
Fractional Numbers
Converting Between Decimal Fractions and Binary Fractions
Decimal Fraction → Binary Fraction
The integer part is converted with the repeated-division method described earlier. The fractional part uses a different method: repeatedly multiply by 2, record the integer part (0 or 1), and continue with the remaining fractional part until it reaches 0.
Example: Convert 0.625 to binary.
0.625 × 2 = 1.25 → record 1, continue with 0.25
0.25 × 2 = 0.5 → record 0, continue with 0.5
0.5 × 2 = 1.0 → record 1, fractional part is 0, stop
Reading top to bottom: 0.101(2)
Verification: 1 × 2^(-1) + 0 × 2^(-2) + 1 × 2^(-3) = 0.5 + 0 + 0.125 = 0.625.
Note that not every decimal fraction can be expressed as a finite binary fraction.
For example, 0.1(10) becomes 0.0001100110011...(2), an infinitely repeating binary fraction.
This is the root cause of floating-point rounding errors in programming.
When a system limits the number of digits (which it must), truncation or rounding occurs, and the stored value drifts from the original input.
Binary Fraction → Decimal Fraction
Same as converting a binary integer to decimal: multiply each digit by 2 raised to its (negative) position, then sum.
Example: Convert 0.1011(2) to decimal.
1 × 2^(-1) + 0 × 2^(-2) + 1 × 2^(-3) + 1 × 2^(-4)
= 0.5 + 0 + 0.125 + 0.0625
= 0.6875
Multiplication and Division via Shift Operations
Shift operations are a fast alternative to multiplying or dividing by powers of 2.
- Left shift (
<<) by n bits → multiply by 2^n - Right shift (
>>) by n bits → divide by 2^n
For example, left-shifting 0101(2) (= 5) by 1 bit gives 1010(2) (= 10), i.e., multiplying by 2.
0 1 0 1 (5)
left shift 1 bit
1 0 1 0 (10 = 5 × 2)
Right-shifting 1000(2) (= 8) by 2 bits gives 0010(2) (= 2), i.e., multiplying by 1/4.
1 0 0 0 (8)
right shift 2 bits
0 0 1 0 (2 = 8 ÷ 4)
Note that right-shifting an integer discards the trailing bits.
For instance, right-shifting 0101(2) (= 5) by 1 bit gives 0010(2) (= 2), and the 1 is lost.
Closing
I wanted to start writing more CS articles, so I added the tag.