I have an RGB colour stored as a uint. I can create this from the RGB values using the bitwise left and bitwise or operator in an expression like this:
colour = r<<16 | g<<8 | b;
I want to do the opposite. I have the final number and I want the r, g and b values. Does anyone know how to do this?
r = (colour >> 16) & 0xff;
g = (colour >> 8) & 0xff;
b = colour & 0xff;
Something like this:
r = ( colour >> 16 ) & 0xFF;
g = ( colour >> 8 ) & 0xFF;
b = colour & 0xFF;
Assuming 8-bit component values. The bitwise-and hex 0xFF
masks pick out just the 8-bits for each component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With