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

#1 2009-12-22 10:01:29

la_appels
Scratcher
Registered: 2007-04-15
Posts: 6

using "letter" on an integer

I was surprised when I tried "letter 5 of N," where N is an integer defined via operators, and it worked. I would appreciate any clarification on why this works.
Thank you.
Lee

Offline

 

#2 2009-12-22 11:17:26

cds56
Scratcher
Registered: 2008-05-02
Posts: 500+

Re: using "letter" on an integer

how many digits were in your variable N?

if say, there were 10, and they were 1234567890, letter # five would be erm, 5.


http://img192.imageshack.us/img192/909/meowdevlogo.pnghttp://i32.tinypic.com/pucti.png

Offline

 

#3 2009-12-22 12:59:38

la_appels
Scratcher
Registered: 2007-04-15
Posts: 6

Re: using "letter" on an integer

My numbers vary in length, but your example is exactly what I get. However, I expected an integer to be represented by a 64-bit string of 0s and 1s (taking into consideration 2-complement or not). So, I am wondering if "letter" is converting the integer to a string?

All this came from my surprise to find integers greater that 2 ** 64 show up in my calculations (e.g., computing factorials that should have either produced an error or switched to floating point). For example, 24! looks like and integer and is correct, but when I divide by two, I get a truncated floating point number. However, when I add 100 to 24!, the result is still an integer and is correct.

Just confused.

Lee

Offline

 

#4 2009-12-22 13:44:46

cds56
Scratcher
Registered: 2008-05-02
Posts: 500+

Re: using "letter" on an integer

That is strange, but my assumption is that 'letter' is converting integer, into string, and then parsing the string into a 32 or 64 bit integer.

for instance what the code may look like in a written language:

Code:

C#

string strTest = "156276";
//See, strTest is still a string
int nTest = Int32.parse(strTest);
//converting

but wait, that only converts a string to integer.

bah, I'm sure there is a way to get a character, from it.


http://img192.imageshack.us/img192/909/meowdevlogo.pnghttp://i32.tinypic.com/pucti.png

Offline

 

#5 2009-12-23 18:41:52

technoguyx
Scratcher
Registered: 2008-10-18
Posts: 1000+

Re: using "letter" on an integer

I guess it's because Scratch variables count as strings and intengers to ease programming (they're strings in some blocks such as letter [] of [], and intengers in others like [] > []).


http://getgnulinux.org/links/en/linuxliberated_4_78x116.png

Offline

 

Board footer