ok so I had to do a program that represents numbers from different radix to some other radix...
The part I got stuck is the following: i.e. I want to convert 123.625 (radix 10) to radix 3. The output is 11120.1212121212121212..... any ideea of a pseudocode/C code to detect whenever the fractional part is in an infinite loop, or not? (PS: I'm storing the fractional part in an array)

6 Years
Discussion Span
Last Post by gusano79

With finite storage, you can never detect all repeating decimals correctly. Say you completely fill up your fractional part array with the digits 1, 2, 0, 1, 2, 0, 1, 2, 0 (small array for example purposes). You might be tempted to say that it's 0.(120), but what if it's really 0.(1201201201), which is a completely different rational number?

Not much you can do about that. But here's a technique for converting decimal to binary that does the conversion and has some built-in detection for repeating representation. I don't know if this is anything like what you're already doing, but it looks like this could be easily adapted to whatever radix you want.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.