Sub topic 8
Fractional Parts in Other Bases
Assume you know place value, powers, fractions, and division with remainders. The same place-value rule used for whole numbers also works to the right of the radix point. The radix point is the base-system version of the decimal point.
Fractional place values
In base \(b\), the first place to the right of the radix point has value \(b^{-1}\), the next has value \(b^{-2}\), and so on.
For example,
\[ (0.231)_4=2(4^{-1})+3(4^{-2})+1(4^{-3}) \]
\[ =\frac{2}{4}+\frac{3}{16}+\frac{1}{64} =\frac{32+12+1}{64} =\frac{45}{64}. \]
The subscript shows the base. Without a subscript, numbers are usually assumed to be in base 10.
| Base | First fractional place | Second fractional place | Third fractional place |
|---|---|---|---|
| 2 | \(1/2\) | \(1/4\) | \(1/8\) |
| 5 | \(1/5\) | \(1/25\) | \(1/125\) |
| 10 | \(1/10\) | \(1/100\) | \(1/1000\) |
| 16 | \(1/16\) | \(1/256\) | \(1/4096\) |
A fractional numeral is therefore a sum of digit-weight products:
\[ (a2a1a0.a{-1}a{-2})b =a2b^2+a1b+a0+\frac{a{-1}}b+\frac{a_{-2}}{b^2}. \]
Converting a base-\(b\) fraction to decimal
Expand each digit using its place value. For example,
\[ (12.13)_5 =1(5^1)+2(5^0)+1(5^{-1})+3(5^{-2}) \]
\[ =5+2+\frac15+\frac3{25} =7+\frac8{25} =7.32. \]
This method works for any base, including binary and hexadecimal.
from fractions import Fraction
def from_base_fraction(whole, fractional, base):
value = int(whole, base)
for position, symbol in enumerate(fractional, start=1):
value += int(symbol, base) * Fraction(1, base ** position)
return value
print(from_base_fraction("12", "13", 5)) # 183/25The result is displayed as an exact fraction because many base-\(b\) fractions do not have finite decimal forms.
Converting a decimal fraction to another base
To convert a fraction between 0 and 1 from decimal to base \(b\):
- Multiply the fraction by \(b\).
- Record the integer part as the next digit.
- Keep the fractional part.
- Repeat until the fraction becomes zero or a pattern repeats.
For \(0.625_{10}\) in base 2:
\[ 0.625\times2=1.25 \]
The first digit is 1, and the remaining fraction is 0.25.
\[ 0.25\times2=0.5 \]
The next digit is 0.
\[ 0.5\times2=1.0 \]
The next digit is 1, so
\[ 0.625{10}=0.1012. \]
For a number greater than 1, convert the whole part and fractional part separately, then join them with the radix point.
A fraction terminates in base \(b\) when its reduced denominator has no prime factors other than those in \(b\). Thus \(3/8\) terminates in base 2 because \(8=2^3\), but \(1/3\) repeats in base 2.
Exercise
Convert \(0.3125_{10}\) to base 2.
Show answer
Multiply repeatedly by 2: \(0.3125\to0.625\to1.25\to0.5\to1.0\). The recorded digits are \(0101\), so \(0.3125{10}=0.01012\), or \(0.0101_2\) when leading fractional zeros are retained.