When converting from base10 to base5 data representation, how do I deal with floating point numbers?

41 Views Asked by At

(Note: This question was originally on StackOverflow. I was recommended to ask here instead.)

In regards to data representation, I am bit confused at how I would go about dealing with floating point numbers when manually converting between bases.

For example, the number 0.734, I wanted to convert using a division method. (Dividing by base I was trying to convert to)

0.734/5 = 0.146 with a remainder of 0.004

In the case of whole numbers, I could just do this with a division conversion of, say, 734 instead:

734/5 = 146 remainder 4
146/5 =  29 remainder 1
29/5  =   5 remainder 4
5/5   =   1 remainder 0
1/5   =   0 remainder 1

So 734 base 10 in base 5 would be 10414

However, I am not familiar with anything I can do with non-whole-number remainders. And regardless, when placing 0.734 into any converter, I get the result (0.33133333...). I am currently learning preliminary knowledge for assembly, so understanding how this works exactly is important to me.

2

There are 2 best solutions below

0
On BEST ANSWER

$$(.734)\cdot 5 = 3.67 \\ (.67) \cdot 5 = 3.35 \\ (.35) \cdot 5 = 1.75 \\ (.75) \cdot 5 = 3.75 ...$$ You keep mutiplying by $5$ and on next line drop the integer part. Since in the last step your next remainder is $.75$ again, the digit 3 just repeats forever.

To read off the answer, look at right column. Start with the "decimal point" [but it's a base 5 point not really decimal] and read off the integer parts of the right column going down, here 3,3,1,3,... [it would be all 3 from there . Hence .3313333...]

Note this calculation assumes you started out with exactly $.734$ to convert. If that was just an appoximation of some more accurate value, one would need more digits of the accurate value.

0
On

To add to @coffeemath's answer, the reason you switch to multiplying is because of what happens to place value when you move from the left side of the point to the right.

For base 5, place values are $$... 5^3, 5^2, 5^1, 5^0\cdot5^{-1},5^{-2},5^{-3}, ...$$ Or $$... 5^3, 5^2, 5^1, 5^0\cdot\frac 1 {5^1},\frac 1 {5^2},\frac 1 {5^3},...$$ The first division by 5 of the whole number part of a decimal number extracts the value of the $5^0$ place. Continued division builds to the left.

Because on the right side of the point we flip to reciprocals of powers of 5, to extract digits from the fraction part we must multiply, not divide.

The first multiplication by 5 of the fraction part of a decimal number extracts the value of the $5^{-1}$ place. Continued multiplication builds to the right.