Member Avatar for terrah

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)

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.