Can we please have bitwise operators with scratch ?
They allow us to code new and high power algorithms which are extremely fast
though they are a bit advanced but if a person has the knowledge of mod , e , ln then they should have basic knowledge of Binary ..
kindly support :-)
Offline
Mokat wrote:
I don't know when I would use them, but I can see where it would be helpful for some people. Support
![]()
Ever heard about huffman coding ??
with bitwise operators we can logically compress our datacontaining projects or can even decode real world files in scratch :-)
Offline
I'm not even sure what these are; care to explain?
Offline
scimonster wrote:
I'm not even sure what these are; care to explain? :P
Well, there are several
I don't know if bit shifts count, but I'll say 'em anyway.
Generally done with >> and << commands in other programming languages, these shift a number over. So say if you have 000110100101110, if you do << 2 then you'll get 011010010111000. >> goes the other way and truncates.
NOT does logical negation, so NOT 100101 is 011010. It's sometimes referred to with ~.
AND takes two numbers. If both have a one in the same place, then the result will have it. So 1101 AND 0111 will give you 0101. It's sometimes done with &, as opposed to the logical AND (&&).
OR takes two numbers. If either number has a one in a place, the result has a one in that place. 01101001 OR 10011000 will give you 11111001. Often represented by |, as opposed to the logical OR (||).
XOR, or exclusive or, takes two numbers. If only one number has a one in a place, then that place in a result will have a one. 01101 XOR 11111 equals 10010. This is commonly used for inverting an image and is often represented by ^ in programming.
Here's more explanation.
Last edited by veggieman001 (2012-04-29 11:24:55)
Offline
They are operators that operate on the binary code of the operands. There is:
() & () -- (and - AKA mask) This places a 1 in places only where both operands have a 1, 0s everywhere else.
() | () -- (or) This places a 0 in places only where both operands have a 0, 1s everywhere else.
! () -- (not) This inverts the binary code (1s where there are 0s and 0s where there are 1s)
() ^ () -- (xor) This places a 1 everywhere where the bits are different in both operands and 0 where they are the same, However, this might be confused with exponentiation.
() >> (n) -- (right shift) This deletes the first n bits from the end of the binary string
() << (n) -- (left shift) This adds n 0s on the end of the binary string
EDIT: oops, outposted by veggieman.
Last edited by joefarebrother (2012-04-30 12:05:24)
Offline
veggieman001 wrote:
scimonster wrote:
I'm not even sure what these are; care to explain?
![]()
Well, there are several
I don't know if bit shifts count, but I'll say 'em anyway.
Generally done with > > and < < commands in other programming languages, these shift a number over. So say if you have 000110100101110, if you do << 2 then you'll get 011010010111000. > > goes the other way and truncates.
NOT does logical negation, so NOT 100101 is 011010. It's sometimes referred to with ~.
AND takes two numbers. If both have a one in the same place, then the result will have it. So 1101 AND 0111 will give you 0101. It's sometimes done with &, as opposed to the logical AND (&&).
OR takes two numbers. If either number has a one in a place, the result has a one in that place. 01101001 OR 10011000 will give you 11111001. Often represented by |, as opposed to the logical OR (||).
XOR, or exclusive or, takes two numbers. If only one number has a one in a place, then that place in a result will have a one. 01101 XOR 11111 equals 10010. This is commonly used for inverting an image and is often represented by ^ in programming.
Here's more explanation.
Lovely post :-) +1
These are not generally used but when used these can do awesomness say for instance i will consider an mp3Frame header :-) its just 4 bytes but these 32 bits are soo nicely written that each bit has its own meaning :-) and when u wanna go to the level of handling bits , bitwise operators are the only solution you have :-)
here is a small example of there use in javascript
/* Snippet to read mp3 frame header * /
var ver = ( buffer.head[1] & 0x18)>>>3;
var layer = ( buffer.head[1]& 0x6 )>>>1;
var crc = ( buffer.head[1]&0x1 );
var bitrate = ( buffer.head[2] & 0xF0 )>>>4 ;
var samplerate = ( buffer.head[2] & 0xC)>>> 2;
var padding = ( buffer.head[2] & 0x2)>>>1;
var priv = ( buffer.head[2]& 0x1 );
var channel = ( buffer.head[3] & 0xC0 )>>>6;
var jsExt = ( buffer.head[3]& 0x30)>>> 4; /* joing stereo ext */
var cpyrite = ( buffer.head[3]& 0x9)>>> 3;
var orig = ( buffer.head[3] & 0x4 )>>>2;
var Emph = ( buffer.head[3] & 0x3 );Now each element in buffer has like 1 byte of data but you can see how much data are we extracting from just 3 bytes of data :-) makes sense ?? It can open a whole new paths for programmers using scratch ,
moreover
they are extremely fast
Last edited by fanofcena (2012-04-30 03:50:39)
Offline
trinary wrote:
It would be nice, but Scratch...is for learning to program.
It's primarily for beginners.
It may be confusing for them.
However, I still support.
Well scratch has a lot of things in the arithimetics secion which can confuse :-) , and by the way language without bitwise operators cannot be called a real programming language now can it ?
Offline