When given large numbers, the hexdec function automatically converts the value to scientific notation. So, "aa1233123124121241" as a hexadecimal value will be converted to "3.13725790445E+21". If you're converting a hexadecimal value that represents a hash value (md5 or sha), then you need every single bit of that representation to make it useful. By using the number_format function, you can do that perfectly. For example :

The issue I've seen with the existing hex to dec conversion routines is the lack of error-trapping. I stick to the theory that one should try to cover ALL the bases when writing a generalized routine such as this one. I have a varied background that covers a wide variety of design/development languages, on the web as well as desktop apps. As such I've seen multiple formats for writing hex colors.

For example, the color red COULD be written as follows:#ff0000&Hff0000#ff&Hff

Therefore I have written a function that is case-insensitive and takes into account the chance that different developers have a tendency to format hex colors in different ways.

As you can see, the function "convert_color" accepts a hex # in most acceptable formats and returns an associative array. [success] is set to TRUE if the function succeeds and FALSE if not. The array members [r], [g] and [b] hold the red,green and blue values respectively. If it fails, [error] holds a custom error message.

"strip_chars" is a support function written to remove the unwanted characters from the hex string, and sends the concatenated string back to the calling function. It will accept either a single value or an array of values for the characters to remove.