Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 1
    It needs to pad the hex strings, such as: ("00" + ((this >> 24) & 0xFF).toString(16)).slice(-2) + ("00" + ((this >> 16) & 0xFF).toString(16)).slice(-2) + ("00" + ((this >> 8) & 0xFF).toString(16)).slice(-2) + ("00" + (this & 0xFF).toString(16)).slice(-2);
    – Thymine
    Commented Feb 6, 2014 at 22:38
  • 4
    I'm converting a bunch of music genre tags to background colors and this saved me a lot of time. Commented Feb 25, 2016 at 5:18
  • I wish I could convert this to php.
    – Nimitz E.
    Commented Jun 11, 2016 at 10:17
  • 15
    I have some problems with almost same colours for similar strings, for example: intToRGB(hashCode('hello1')) -> "3A019F" intToRGB(hashCode('hello2')) -> "3A01A0" And I enhance your code by adding multiplication for final hash value: return 100 * hash;
    – SirWojtek
    Commented Aug 24, 2017 at 1:43
  • Don't forget to add '#' like return "#" + "00000".substring(0, 6 - c.length) + c; Commented Mar 21, 2019 at 19:51