Math Related : Hex-to-RGB Conversion | JavaScriptSource

Math Related : Hex-to-RGB Conversion

Alexei Kourbatov Dec 19, 2008

General

Use this script to convert a hex color string to numeric RGB values of the same color. Great for matching colors. Easy to implement!



R: G: B:

Notes

Source Code

Paste this source code into the designated areas.

Head

Paste this code into the HEAD section of your HTML document.


Body

Paste this code into the BODY section of your HTML document


Leave a Response

(1 comment)

Many people are using short hex colors, where fff is the same as ffffff, 222 is the same as 22222, etc. This converter could be modified to also convert short hex by checking the hex string length and branching to two routines. It would also be nice to validate the input.

Phil Frisbie Dec 19, 2008