java - Why do we use >> to get colour values from RGB? -


I know that to get color values ​​from RGB

  b = rgb & Gt; & Gt; 0g = RGB & gt; & Gt; 8R = RGB & gt; & Gt; 16   

Does anyone tell me why does this work? Each of them is correct 8 bits? Do not & gt; & Gt; N give n bits first? How does it work for B and R?

Actually it should not work unless you strip the bar at some point in the unnecessary bits.

& gt; & Gt; is the correct shift operator, where zero bits are sent from the feed and right to the rolling bits. BitBasket (left) assume that the 24-bit RGB value has the following bit, eight color per capita: < rrrrrrrrggggggggbbbbbbbb

Right-transfer that gives you 0 bits from the same value, it gives you the rrrrrrrrgggggg when you move correctly by eight bits , And corrected by sixteen bits, gives rrrrrrrr .

So you can see that the three shifts give each of the three color values ​​in the "lower" (to the right) eight bits. One more legal way to do this would be to ensure that <25> ( 0xff in hex) will be and , but at least eight bits to zero Will be cleared: B = (RGB) & amp; 0xff; G = (RGB => 8) & amp; 0xff; R = (RGB => 16) & amp; 0xff;

See a more detailed description of bitwise operators.

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -