Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Decimal to Binary
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
heesoup




PostPosted: Sun May 31, 2009 9:08 pm   Post subject: 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)



Turing:

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..
Sponsor
Sponsor
Sponsor
sponsor
Diablo117




PostPosted: Sun May 31, 2009 9:18 pm   Post subject: 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:

Spoiler:

astring := intstr(remainder)+astring
TW iz Rippin




PostPosted: Tue Mar 20, 2012 11:02 am   Post subject: RE:Decimal to Binary

code:

var base_10 : int
get base_10
put intstr (base_10, 0, 2)
Raknarg




PostPosted: Tue Mar 20, 2012 11:54 am   Post subject: RE:Decimal to Binary

TW, dont necro post. Notice how this topic is dated back in 2009.
TW iz Rippin




PostPosted: Wed Mar 21, 2012 10:40 am   Post subject: Re: RE:Decimal to Binary

Raknarg @ Tue Mar 20, 2012 11:54 am wrote:
TW, dont necro post. Notice how this topic is dated back in 2009.


my bad didnt see that
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: