I didn't check it in detail, but your false colors may most likely be caused by register overflows, due to up-rounding. Any color, red, green or blue should never be higher than 255.
Probably you should rather try to delete less significant bits to achieve the effect you may be after.
kind of
red=red and %11111000
green=green and %11111000
blue=blue and %11111000
rgb= (red shl 16) or (green shl 8) or blue
this will erase the 3 least significant bits, so a color channel will always be 0,8,16,24... etc.
Probably you should rather try to delete less significant bits to achieve the effect you may be after.
kind of
red=red and %11111000
green=green and %11111000
blue=blue and %11111000
rgb= (red shl 16) or (green shl 8) or blue
this will erase the 3 least significant bits, so a color channel will always be 0,8,16,24... etc.