>> and << operators | SoloLearn: Learn to code for FREE!


>> and << operators

So I red that operators "<<" and ">>" are used to shift a bit pattern, respectively, to the left and to the right. But can someone name a case when such thing is useful, couse it seems an utterly useless thing to do. Thank you for your answer in advance!

1/6/2020 10:04:42 PM

Vitaliy Reshetar

3 Answers

New Answer


It is very useful when you get to do projects on the "deeper level" (electronics, hardware, and such). Some bits trigger certain things and sometimes you want to know if its on or off, for example. One higher level example I have used this in is when I make games, I sometimes use an image as a map. Red represents blocked tiles Green represents the player Blue represents an enemy I get the RGB value and... Red is stored as FF0000 Green is 00FF00 Blue is 0000FF Then I & 0xFF to get an integer to get Red we shift 16 bits right. If it has a value, then we add a block tile to the map Green we shift 8. If value, add player Blue we dont shift, but if value, add enemy. Outside of a learning environment, thats the only time I use it; I dont mess with electronics much anymore so Im not really dwelling much



「HAPPY TO HELP」, oh I got it, now it seems indeed pretty useful 😂 Thanks!