I am trying to create an LMC assemble code that will allow a user to put two inputs: a decimal number and a base that the number should be converted to. The code should be able to convert any decimal number to any base between 2 and 9 included.
I am aware that the division is not available on LMC: I can use subtractions. Lets say, from 12 decimal to base 3, I am able to get 12-3-3-3-3= 4, but how can I make the code understand that the rest of the division 12/3= 4 and rest of the division is 0 and 4-3=1 but 4/3=1,... so the rest of the division is 1-3=-2 and 1/3 is 0,33... so the rest is 1. Now reading it in opposite sense, 12 decimal to base 2 is 110.
But again, even the 1-3= -2: how can I make it understand that the rest is 1?
Also, how can I make the code understand it's within which base? Do I create a long code first for detecting the base? And let's say it's going to BRA
depending which base it is, then I'm not even sure if it's the same algorithm for all the bases...
I am a bit confused here, but even if someone can help me understand how to make the code for getting the remainder of the division, that's gonna help me a lot.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…