1

In processing what is the meaning of this operator?

<< and >>

Sushanth --
  • 55,259
  • 9
  • 66
  • 105
user2321978
  • 49
  • 1
  • 3

4 Answers4

2

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.

Bryan Hong
  • 1,483
  • 13
  • 28
1

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.

Elazar
  • 20,415
  • 4
  • 46
  • 67
0

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!

jesses.co.tt
  • 2,689
  • 1
  • 30
  • 49
0

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

v.k.
  • 2,826
  • 2
  • 20
  • 29