Post Reply 
Base converter with fractions?
01-26-2017, 06:57 PM (This post was last modified: 01-26-2017 07:35 PM by Han.)
Post: #6
RE: Base converter with fractions?
Here's the math for this specific example. A general program is left as an exercise for the diligent reader.

3.142 = 3 + 0.142

Convert the whole number part into base 7. Since it is only 3, then we are done. This leaves 0.142 for conversion to \( 0.d_1 d_2 d_3 \dotsm \) where the \( d_i \) are 0 through 6. Note that if we multiply the fractional part by 7 then we will get a value that is non-negative and strictly less than 7.
\[
\begin{align*}
0.142 & = 0.d_1 d_2 d_3 \dotsm \\
7\cdot 0.142 & = d_1 + 0.d_2 d_3 d_4 \dotsm\\
0.994 & = d_1 + 0.d_2 d_3 d_4 \dotsm \\
\end{align*}
\]
Therefore \( d_1 = 0 \). Now repeat...
\[
\begin{align*}
0.994 & = 0. d_2 d_3 d_4 \dotsm \\
7\cdot 0.994 & = d_2 + 0.d_3 d_4 d_5 \dotsm\\
6.958 & = d_2 + 0.d_3 d_4 d_5 \dotsm \\
\end{align*}
\]
Therefore \( d_2 = 6 \). Rinse and repeat (subtract the integer part and repeat for the fractional part) for as many digits as you need. There should be no round-off error when using BCD math (until you get to bases where the "digits" are represented by more than a single numeral in base 10 -- hence the \( 12/\log_{10}(b) \) limitation), but you might possibly be off using the HP Prime's base-2 representation of floating points.

EDIT: For those who just want the answer: The integer portion of a number can be converted to various bases using known methods. The "hard" part is the fractional portion. However, the fraction portion \( d \) is always such that \( 0 \le d < 1 \). So if \( b \) is the base, then \( 0 \le bd < b \). If \( 0.d_1 d_2 d_3 \dotsm \) is the base-\(b\) representation of \(d \), then \( bd\) is \( d_1 + 0.d_2 d_3 d_4 \dotsm \). Hence \( d_1 \) is the integer part of \( bd \).

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
Base converter with fractions? - Joe Horn - 01-15-2017, 05:53 AM
RE: Base converter with fractions? - Jan_D - 01-22-2017, 03:13 PM
RE: Base converter with fractions? - Jan_D - 01-26-2017, 12:38 PM
RE: Base converter with fractions? - Han - 01-27-2017, 05:00 AM
RE: Base converter with fractions? - Han - 01-26-2017 06:57 PM
RE: Base converter with fractions? - Jan_D - 01-28-2017, 01:42 PM
RE: Base converter with fractions? - Han - 01-27-2017, 04:37 AM
RE: Base converter with fractions? - Jan_D - 02-02-2017, 05:26 PM
RE: Base converter with fractions? - Jan_D - 02-03-2017, 01:51 PM
RE: Base converter with fractions? - Jan_D - 02-21-2017, 05:59 PM
RE: Base converter with fractions? - Han - 02-21-2017, 07:30 PM
RE: Base converter with fractions? - Jan_D - 02-22-2017, 06:03 PM
RE: Base converter with fractions? - Han - 02-03-2017, 02:31 PM
RE: Base converter with fractions? - Jan_D - 02-03-2017, 05:52 PM
RE: Base converter with fractions? - Jan_D - 02-13-2017, 01:14 PM
RE: Base converter with fractions? - Han - 02-13-2017, 01:27 PM



User(s) browsing this thread: 1 Guest(s)