
-----------------------------------
heesoup
Sun May 31, 2009 9:08 pm

Decimal to Binary
-----------------------------------
What is it you are trying to achieve?
Convert a base 10 number to binary.


What is the problem you are having?
The answer seems to be incorrect.

Describe what you have tried to solve this problem
I know that I have to invert the digits for the answers for the right binary answer...but...how..?


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)




var x,remainder,quotient: int
put "type a number from 0 to 255." ..
get x



loop  
remainder:=x mod 2
quotient:=x div 2
x:=quotient
exit when quotient=0
end loop
put remainder..






Please specify what version of Turing you are using
the newest one I think..

-----------------------------------
Diablo117
Sun May 31, 2009 9:18 pm

Re: Decimal to Binary
-----------------------------------
Your remainder constantly changes. If you put the remainder inside the loop, you will see that the digits do in fact appear. What you need to do is store the remainder in reverse order :

for example

astring := astring+intstr(remainder)

that should be inside your loop. it isnt in reverse order but I leave it up to you to figure that out.

if your too lazy to think:


astring := intstr(remainder)+astring


-----------------------------------
TW iz Rippin
Tue Mar 20, 2012 11:02 am

RE:Decimal to Binary
-----------------------------------
[code]
var base_10 : int
get base_10
put intstr (base_10, 0, 2)
[/code]

-----------------------------------
Raknarg
Tue Mar 20, 2012 11:54 am

RE:Decimal to Binary
-----------------------------------
TW, dont necro post. Notice how this topic is dated back in 2009.

-----------------------------------
TW iz Rippin
Wed Mar 21, 2012 10:40 am

Re: RE:Decimal to Binary
-----------------------------------
TW, dont necro post. Notice how this topic is dated back in 2009.

my bad didnt see that
