CS question: base converter? (CS=Computer science)

DAM

Diamond Member
Jan 10, 2000
6,102
1
76
I need to be able to get a number and a base, and then turn the number using the inputed base, i cant think of the damn sudo code, anyone got any tips?


ohh yeah this is C programming.



dam(gear)
 

DAM

Diamond Member
Jan 10, 2000
6,102
1
76
windogg, ofcourse i mean pseudo, arent you in with the cool cs slang? its sudo baby.








dam(sudo chop)
 

iamwiz82

Lifer
Jan 10, 2001
30,772
13
81
DAM, i wrote a program that could convert any based number to any base, but i cant think of any of the code right now. If you wait, i cant get you it. Its in Java, though.

to change base, take a number, like 123 base 10, convert it to base 5:

for(n=0;;n++)
x=5^n
if(x>123)
end loop
else
keeplooping

subtract x from 123 as long as the number is above 0 123-25-25-25-25=23 R:4
store the number of times it loops, with a for loop

take the remainder of the previous subraction, 23 and subtract x^n-1 23-5-5-5-5=3 R:4
store that number 3

and repeat til the number is smaller than the base, so the answer would be 4 4 3




 

DAM

Diamond Member
Jan 10, 2000
6,102
1
76
iamwiz: yeah i would love to see your prog, and thanks for the info too.





dam()