Number with fraction conversion...

Let's talk about algorithms!

Moderator: Board moderators

Post Reply
tytus
New poster
Posts: 4
Joined: Wed Nov 17, 2004 9:09 pm

Number with fraction conversion...

Post by tytus »

Is there any fast algorithm to convert numbers with fractions (very big numbers - up to 400 digits) between different bases (where the base ib is 2<=b<=36)??
For example:1100,1100 (base 2) to number with base 7...



PLEASE HELP!!!
misof
A great helper
Posts: 430
Joined: Wed Jun 09, 2004 1:31 pm

Post by misof »

For integers you can use the same algorithm as when converting e.g. from base 10 to base 2 -- divide the number by the new base, the reminder is the last digit of its new representation, and so on.

E.g.
10110 (base 2) to base 7:
10110 : 111 = 11, reminder 1 => last digit is 1
11 : 111 = 0, reminder 11 => previous digit is 11 (base 2), i.e. 3
Therefore 10110 (base 2) = 31 (base 7):

There is a problem with rational numbers -- the representation of a number may be finite in some bases and infinite in other ones. E.g. consider the number 0.2 (base 10). In base 2, this number is 0.0011001100110011...
Post Reply

Return to “Algorithms”