To insert the value, start by using a mask to clear out the 8-bits of the pixel corresponding to the given color channel. For example, in the case of red, shift an 8-bit mask of ones left 16 bits, invert it (using the ~ operator), and “and” (&) this mask with the RGB value, which clears out the 8 bits of red and leaves the other bits unchanged. Next, shift the parameter value (red, in this case) left the same number of bits (16, in the case of red) and “or” (|) the shifted value into the pixel value.
int getRed(){
red = (Pixel>>16);
red = ~Pixel;
red = Pixel<<16 | Pixel;
return red;
}
What am I doing wrong according to the directions?
redvalue in subsequent operations. sinceredis always being assigned from some operation onPixel, you aren't accumulating the 3 operations, just doing 3 independent operations.