1. Senior Member
Join Date
Mar 2013
Posts
123
Rep Power
0

Base conversion

Hello forum. I am confused. I am writing a method that takes in a int value and a base and from those two find the base number . For example: The method takes a number, say 342, and converts it to a base (any base).

I understand the algorithm, cant fathom the code

Heres what I know

value % base = first digit starting from right
(value/base) % base = second digit starting from the right
(value/base^2)% base = third digit starting from right...

,... and so forth.

I am not sure how to write this loop. I was thinking a while...I cant see this. Can some one help me better understand how to loop this? THanks in advance

2. Senior Member
Join Date
Jan 2013
Location
Northern Virginia, United States
Posts
5,661
Rep Power
9

Re: Base conversion

Get some paper and pencil and go through the algorithm by hand. You should notice a repetitive pattern. Also, do this when converting decimal to decimal. It might make it easier to visualize.

Regards,
Jim