RGB to Hex Converter Online Tool
About RGB to Hex Converter Online Tool:
This online RGB to Hex converter tool helps you to convert one RGB color (base 10) into a Hex color (base 16), and test the result color within the website.
RGB Color System:
The RGB color ("R" stands for "Red", "G" stands for "Green", "B" stands for "Blue") is specified how much red, green and blue light are combined together. The syntax is rgb(16,110,190)
.
Hex Color System:
the Color System used in HTML is also be written down as Hex number, from #000000
(pure black) to #FFFFFF
(pure white). For example, #123456
means the Red is "12" (in range
"00" to "FF"), the Green is "34", the Blue is "56". The Hex color system also support 3-digits color, for example, color #e1a
is equivalent to #ee11aa
.
How to convert from RGB to Hex?
Step 1: Get the decimal number of each sub-color (Red, Green and Blue).
Step 2: Convert each decimal number into hex number.
Step 3: Write the Hex Color result String in correct syntax.
Example: Convert RGB Color "rgb(16,110,190)" to Hex Color (result is "#106ebe"):
Step 1: | RGB Color "rgb(16,110,190)": Red(16), Green(110), Blue(190) |
Step 2: | Red: (16)->(0x10), Green: (110)->(0x6e), Blue: (190)->(0xbe) |
Step 3: | RGB Color "rgb(16,110,190)" -> "#106ebe" |
More information:
Wikipedia (Web colors): https://en.wikipedia.org/wiki/Web_colors
Wikipedia (RGB color model): https://en.wikipedia.org/wiki/RGB_color_model
Convert RGB to Hex with Python:
import re def rgb_to_hex(rgb_color): rgb_color = re.search('\(.*\)', rgb_color).group(0).replace(' ', '').lstrip('(').rstrip(')') [r, g, b] = [int(x) for x in rgb_color.split(',')] # check if in range 0~255 assert 0 <= r <= 255 assert 0 <= g <= 255 assert 0 <= b <= 255 r = hex(r).lstrip('0x') g = hex(g).lstrip('0x') b = hex(b).lstrip('0x') # re-write '7' to '07' r = (2 - len(r)) * '0' + r g = (2 - len(g)) * '0' + g b = (2 - len(b)) * '0' + b hex_color = '#' + r + g + b return hex_color rgb_input = 'rgb(7,110,190)' hex_output = rgb_to_hex(rgb_input) print('Hex color result is:{0}'.format(hex_output)) ------------------- Hex color result is:#076ebe