RGBToHEX does exactly the opposite of HEXToRGB: it combines the three components red, green and blue to an RGB value, which can be converted to e.g. Hex
(red, green, blue byte)
| 41 | // RGBToHEX does exactly the opposite of HEXToRGB: |
| 42 | // it combines the three components red, green and blue to an RGB value, which can be converted to e.g. Hex |
| 43 | func RGBToHEX(red, green, blue byte) (hex uint) { |
| 44 | // Sets the bits of blue in position 1-8, green in 9-16 and red in 17-24 |
| 45 | |
| 46 | // Red: 00110100 |
| 47 | // Green: 10011000 |
| 48 | // Blue: 11011011 |
| 49 | // RGB: |
| 50 | // R << 16: [00110100] 00000000 00000000 | |
| 51 | // G << 8 : 00000000 {10011000} 00000000 | |
| 52 | // B : 00000000 00000000 <11011011> = |
| 53 | // [00110100] {10011000} <11011011> |
| 54 | return (uint(red) << 16) | (uint(green) << 8) | uint(blue) |
| 55 | } |
no outgoing calls