Link to home
Start Free TrialLog in
Avatar of hengck23
hengck23

asked on

What is the use of the shift operator <<?

Dear All,

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?

Thank you.

With Best Regards
HCK
ASKER CERTIFIED SOLUTION
Avatar of drichards
drichards

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial