Scheme Exercises

back to exercise list       previous     next

Group:     Exercise: 32/48 

ChangeBase:  Change a number from one base-representation to another base-representation

(Quite challenging): Create the function ChangeBase(N, from-base, to-base) that will be given a non-negative integer, and the base it's written in (an integer > 1) and the base it should end up being written in (an integer > 1), and will do the conversion.
(Hint: try converting to and from base 10)
For instance:
(ChangeBase 6 10 2) ; -> 110 (converted 6 from base 10 to base 2)
(ChangeBase 110 2 10) ; -> 6 (converted 110 from base 2 to base 10)
(ChangeBase 110 2 3) ; -> 20 (converted 110 from base 2 to base 3)