What is the use of the shift operator <<?
Posted on 2004-09-05
I am writing the code for RGB to gray level conversion.
The NTSC standard for luminance:
I = 0.299r + 0.587g + 0.114b
While searching the web, i came across the code that does the task:
#define RGB_SCALE 14
#define cR (int)(0.299*(1 << RGB_SCALE) + 0.5)
#define cG (int)(0.587*(1 << RGB_SCALE) + 0.5)
#define cB ((1 << RGB_SCALE) - cR - cG)
//I is greyLevel output
//r is red value
//g is green value
//b is blue value
I = cR*r+cG*g+cB*b;
I = (((I) + (1 << ((RGB_SCALE)-1))) >> (RGB_SCALE));
What is the purpose of the bitwise operations involving RGB_SCALE, especially for the last line of code?
With Best Regards