Reputation: 49
In processing what is the meaning of this operator?
<< and >>
Upvotes: 1
Views: 128
Reputation: 2854
The common use of this operators in Processing is to get colors components from a pixel. The built in red(), green() and blue() functions also does this, but are slower. The color in Processing are stored in 32 bits in a pattern like ARGB alphaRedGreenBlue. Youcan access them like this:
color c = color(240, 130, 20);
int alpha = (c >> 24) & 0xFF;
int red = (c >> 16) & 0xFF;
int green = (c >> 8) & 0xFF;
int blue = c & 0xFF;
println(alpha + " " + red + " " + green + " " + blue);
This snippet is from a article in the wiki: http://wiki.processing.org/w/What_is_a_color_in_Processing%3F There you can read further
Upvotes: 0
Reputation: 2729
As above, they are Bit Shifting Operators, to shift a bit left or right. This works in Java - of which Processing is a library for - as well as other languages, like C++, Python, etc.
As to what it is, it's a fairly low level way to access the bits of a variable itself and change it closer to the actual memory address, which can tend to be faster than accessing / reading the bits as the sotred variable, reassigning it's value, and updating that new value back in the correct address...
There is a good example of it being used in the Color Sorting example in Processing...
File/Sketchbook/Examples/Libraries/Video(Capture)/Color Sorting
Hope that helps!
Upvotes: 0
Reputation: 1483
Have look at this link: http://docs.oracle.com/javase/tutorial/java/nutsandbolts/op3.html. These are bit shift operators.
The signed left shift operator "<<" shifts a bit pattern to the left, and the signed right shift operator ">>" shifts a bit pattern to the right. The bit pattern is given by the left-hand operand, and the number of positions to shift by the right-hand operand.
Upvotes: 2
Reputation: 21595
These are the shift operators. the original purpose is for bit shifting. in C++ and some other languages they are used for stream input and ouput.
Upvotes: 1