MCPcopy Create free account
hub / github.com/TheAlgorithms/Go / RGBToHEX

Function RGBToHEX

conversion/rgbhex.go:43–55  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
43func 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}

Callers 2

TestRGBToHEXFunction · 0.85
BenchmarkRGBToHEXFunction · 0.85

Calls

no outgoing calls

Tested by 2

TestRGBToHEXFunction · 0.68
BenchmarkRGBToHEXFunction · 0.68