Discuss Scratch
- Discussion Forums
- » Advanced Topics
- » Bit Shifts & Intiger Limits
- Mistop
-
51 posts
Bit Shifts & Intiger Limits
In this project here: http://scratch.mit.edu/projects/11823644/#editor
A bit shift is implemented to allow the high scores data to be carried via a cloud variable, and I need to know; can these bit shifts or ‘scrambles’ be done twice to the same imformation without losing any data. I also need to know if there is a maximum number you can get if you re trying to scramble a file - as I need to know if it would be possible to scrambe a word file that uses que-based typing
(typing shown in this project: http://scratch.mit.edu/projects/11852779/)
Thank-you.
A bit shift is implemented to allow the high scores data to be carried via a cloud variable, and I need to know; can these bit shifts or ‘scrambles’ be done twice to the same imformation without losing any data. I also need to know if there is a maximum number you can get if you re trying to scramble a file - as I need to know if it would be possible to scrambe a word file that uses que-based typing
(typing shown in this project: http://scratch.mit.edu/projects/11852779/)
Thank-you.
- bobbybee
-
1000+ posts
Bit Shifts & Intiger Limits
This is very intriguing.
To answer your questions:
1) Repeatable Bitshifts
Absolutely. Bitshifts are symmetric operations, in the sense that you can repeat them many times and get the same effect. The math behind this is as follows:
x=2x/2=4x/4=8x/8..x(2^n)/(2^n)
That being said, there is no benefit of repeating the bit shift (or, depending on your real purpose, performing it all).
2) Integer limits
Unfortunately, yes, there is a limit. I made a quick project: http://scratch.mit.edu/projects/14896176/, which tests exactly this: takes the number 1, and shifts it to the left numerous times until it reaches Infinity. It appears that Scratch's max value is about 2^1024-1, or (this took me a while to find, due to the value being the limit for many programming languages) approximately 1.797693134862315907729305190789×10308.
This being said, there are much more efficient ways to create lists like this. Could you elaborate on why you use the bit shift in the first place.
To answer your questions:
1) Repeatable Bitshifts
Absolutely. Bitshifts are symmetric operations, in the sense that you can repeat them many times and get the same effect. The math behind this is as follows:
x=2x/2=4x/4=8x/8..x(2^n)/(2^n)
That being said, there is no benefit of repeating the bit shift (or, depending on your real purpose, performing it all).
2) Integer limits
Unfortunately, yes, there is a limit. I made a quick project: http://scratch.mit.edu/projects/14896176/, which tests exactly this: takes the number 1, and shifts it to the left numerous times until it reaches Infinity. It appears that Scratch's max value is about 2^1024-1, or (this took me a while to find, due to the value being the limit for many programming languages) approximately 1.797693134862315907729305190789×10308.
This being said, there are much more efficient ways to create lists like this. Could you elaborate on why you use the bit shift in the first place.
- nXIII
-
1000+ posts
Bit Shifts & Intiger Limits
Scratch uses ActionScript's floating point numbers, which lose integer precision after 15 decimal places. But if you use string operations (JOIN, LENGTH, and LETTER OF) instead of multiplication, there will be no practical limit.
- MoreGamesNow
-
100+ posts
Bit Shifts & Intiger Limits
Scratch uses ActionScript's floating point numbers, which lose integer precision after 15 decimal places. But if you use string operations (JOIN, LENGTH, and LETTER OF) instead of multiplication, there will be no practical limit.
Aren't all cloud variables stored numerically and thus restricted to the integer precision of of Scratch (thus making “join” not an effective workaround; sorry haven't used Scratch in a while)?
nXIII says there is an accuracy of 15 decimal places (in other words ~50 bits of accuracy, presumably leaving the rest for magnitude; this is consistent with my knowledge of 64-bit systems, so I would guess his is the answer you're looking for.
bobbybee's “2^1024 - 1” answer is likely near the “maximum value of scratch”, but the bit precision of the number is very likely not this high. In other words, the computer might know the number is about 2^1024, but it has no way of knowing all the less-significant digits. This means that if you try to bit-shift more than about 14 decimal places you'll start losing data.
Edit: apparently the “normal” double datatype has a significand of 53 bits, so you may be able to get away with 16 digits; sorry, I'd work it out / run some tests, but it's late. Goodnight :) did the math, nXIII is right. log(2^53)/log(10) = 15.95; the limit i s 15

Last edited by MoreGamesNow (July 11, 2014 17:03:13)
- Discussion Forums
- » Advanced Topics
-
» Bit Shifts & Intiger Limits