This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2012-09-22 07:36:49

faiqahsan
New Scratcher
Registered: 2012-09-22
Posts: 1

decimal to binary converter

hello! i am trying to make a binary converter...n i m confused that how to use "repeat until" tab in this project.
i mean i am able to convert a specific number to binary form but for any value as a input i have to use "repeat until" tab.please tell me how to do it?

Offline

 

#2 2012-09-22 09:12:43

scmb1
Scratch Team
Registered: 2009-03-19
Posts: 1000+

Re: decimal to binary converter

Which method do you plan to use to convert from decimal to binary? If you use the division by 2, it shouldn't be too hard to work in that "repeat until."

If you use that method, I recommend using one variable for the decimal number (let's call it "decimal"), one for it's binary representation ("binary"), and one for the  in-between answers you get by dividing the decimal number by 2 (I'll call that "a").

You could initially set a equal to the decimal value. Then you could use the repeat until block to repeatedly divide a by 2 until a is 1, rounding a down if it is not evenly divisible. In each repeat, you could also use the join block to add on the remainder of that division to the binary variable.

Those are just some ideas. Let me know if you have any questions.  smile


http://i48.tinypic.com/2z5pqad.png

Offline

 

Board footer