RGB To Hex To RGB Conversion

Introduction

The RGB color model is an additive model in which red, green, and blue (often used in additive light models) are combined in various ways to reproduce other colors. The name of the model and the abbreviation ‘RGB’ come from the three primary colors, red, green, and blue and the technological development of cathode ray tubes which could display color instead of a monochrome phosphoresence (including grey scaling) such as black and white film and television imaging.

A hex triplet is a six-digit, three-byte hexadecimal number used in HTML and CSS, and other computing applications, to represent colors. The bytes represent the red, green and blue components of the color. One byte represents a number in the range 00 to FF (in hexadecimal notation), or 0 to 255 in decimal notation. This represents the least (0) to the most (255) intensity of each of the color components. The hex triplet is formed by concatenating three bytes in hexadecimal notation, in the following order:

Byte 1: red value
Byte 2: green value
Byte 3: blue value

For example, consider the color where the red/green/blue values are decimal numbers: red=36, green=104, blue=160 (a greyish-blue color). The decimal numbers 36, 104 and 160 are 24, 68 and A0 respectively in hexadecimal notation. To obtain the hex triplet, we simply write the three hex bytes together without spaces, thus: 2468A0. If a byte is less than 16 (decimal) or 10 (hex) it must be represented with a leading zero to keep the number of digits in the triplet equal to six. For example, the decimal triplet 0,1,2 would be represented by the hex triplet 000102.

Algorithm

Converting a decimal RGB value to a hexadecimal value is fairly straightforward. RGB values are usually given in the 0-255 range; if they are in the 0-1 range, multiply the value by 255 before conversion. The number of times this number divides into 16 (without rounding) gives us the first hexadecimal digit (between 0 and F, see hexadecimal if unsure). The remainder gives us the second digit. For instance the RGB value 201 divides 12 times into 16, thus the first digit is C. A remainder of 9 gives us the hexadecimal number C9. This process is repeated for each color value. Most modern operating systems have a built-in calculator to perform conversions between number bases; this can also be done with some calculators.

1) from RGB to Hex value
Put RGB values into the text field R, G, and B. Leave the mouse into the one of text fields. And hit the return key. RGB values must be between 0 to 255.
2) from Hex to RGB value
Put Hex value into the text field Hex. Hex value must be 6 digits of "0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, and F". Leave the mouse into the text field Hex. And hit the return key.