I'm making a program that uses C and ARM assembly, and one of the things I need to do is convert a RGB image into a grayscale image. So my professor gave me this code just to understand how it works:

```
int rgb2gray(pixelRGB pixel){
 return  ( (2048*pixel.R + 4096*pixel.G + 512*pixel.B) /(8*1024));
 }

```

This function converts a RGB value to gray.

Anyone can explain how that algorithm is working and why use those exact values (2048, 4096, 512...).