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

#1 2012-02-05 09:46:59

Cos140
New Scratcher
Registered: 2012-02-05
Posts: 5

I need help ASAP!

I am making a binary converter on scratch. It's a project that is due on Monday. I am having trouble getting my sprite to say the answer. For example if I have it marked with a 64, 16, 8, and a 2. I need it to tell me that the answer is 90.

Offline

 

#2 2012-02-05 09:56:24

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: I need help ASAP!

I'm confused. What exactly do you want?  hmm

Offline

 

#3 2012-02-05 10:02:50

Cos140
New Scratcher
Registered: 2012-02-05
Posts: 5

Re: I need help ASAP!

I need to know how to get my sprite to tell me the answer. It's a binary converter so it's only dealing with ones and zeros. So if I have a one where 64, 16, 8, and 2 are I need my sprite to tell me that the answer is 90. If this makes it more clear. I'm confused just trying to write it down.

Offline

 

#4 2012-02-05 11:06:43

scimonster
Community Moderator
Registered: 2010-06-13
Posts: 1000+

Re: I need help ASAP!

Can you please upload your current project; then I might be able to help you better.  smile

Offline

 

#5 2012-02-05 13:01:03

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: I need help ASAP!

scimonster wrote:

Can you please upload your current project; then I might be able to help you better.  smile

It sound like he/she needs a way to find the total of the numbers.

If that's the case, add all the numbers to a list named "numbers".  Create a variable named "counter" and a variable named "result".  Then use:

set [counter  v] to (1)
set [result  v] to (0)
repeat (length of [numbers  v] ) 
set [result  v] to ( (result) + (item (counter) of [numbers  v]) )
change [counter  v] by (1)
end
say (result)
You can replace that last block with whatever you want to use to tell the answer.   smile

Offline

 

#6 2012-02-05 13:11:10

RedRocker227
Scratcher
Registered: 2011-10-26
Posts: 1000+

Re: I need help ASAP!

Yep, Greenatic got it spot on.


Why

Offline

 

#7 2012-02-05 13:24:58

Smozzick
Scratcher
Registered: 2011-10-23
Posts: 100+

Re: I need help ASAP!

Ok so assuming that the places for the binary are kept in a list (1st row is 1, second 2, 3rd 4 etc.).

set (total) to [0]
set (counter) to [0]
repeat [max number of bits of binary number]
change (counter) by [1]
change (total) by (item (counter) of [binarylist v]) * 2^(counter)
end
Something like that...probably replace the 2^counter with values from another list since you can't do ^ in scratch.


http://i50.tinypic.com/ded8m.png

Offline

 

#8 2012-02-05 15:06:06

Cos140
New Scratcher
Registered: 2012-02-05
Posts: 5

Re: I need help ASAP!

I up loaded what I have so far for my project on my page I'm not sure how to get it to be in here.

Offline

 

#9 2012-02-05 15:09:51

Cos140
New Scratcher
Registered: 2012-02-05
Posts: 5

Re: I need help ASAP!

So when you click on the grey box it turns it yellow and the yellow box below it grey and the zero changes to a 1. I need to be able to get my sprite to say the total of the numbers if I had more than one 1 at the bottom.

Offline

 

#10 2012-02-05 17:26:01

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: I need help ASAP!

Cos140 wrote:

So when you click on the grey box it turns it yellow and the yellow box below it grey and the zero changes to a 1. I need to be able to get my sprite to say the total of the numbers if I had more than one 1 at the bottom.

OK, so create a variable named "counter", a variable named "result", and a list called "numbers".  This script, when run, will cause the sprite that runs it to say the answer:

delete [all  v] of [numbers  v]
add (  ( ( [costume #  v] of [Sprite23  v] ) - (1)  ) * (128) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite23  v] ) - (1) ) * (64) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite24  v] ) - (1) ) * (32) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite25  v] ) - (1) ) * (16) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite26  v] ) - (1) ) * (8) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite27  v] ) - (1) ) * (4) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite28  v] ) - (1) ) * (2) )to [numbers  v]
add ( ( ( [costume #  v] of [Sprite29  v] ) - (1) ) * (1) )to [numbers  v]
set [counter  v] to (1)
set [result  v] to (0)
repeat (length of [numbers  v] ) 
set [result  v] to ( (result) + (item (counter) of [numbers  v]) )
change [counter  v] by (1)
end
say (result)

Last edited by Greenatic (2012-02-05 17:29:05)

Offline

 

#11 2012-02-05 17:43:31

Cos140
New Scratcher
Registered: 2012-02-05
Posts: 5

Re: I need help ASAP!

Thank you so much!!

Offline

 

#12 2012-02-05 17:47:45

Greenatic
Scratcher
Registered: 2009-05-03
Posts: 1000+

Re: I need help ASAP!

Cos140 wrote:

Thank you so much!!

No problem.   smile

Offline

 

Board footer