Created
December 14, 2015 17:31
-
-
Save Dammmien/1733eef8b06838b42fc4 to your computer and use it in GitHub Desktop.
RGB to Hex and Hex to RGB
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rgbToHex = ( r, g, b ) => "#" + ( ( 1 << 24 ) + ( r << 16 ) + ( g << 8 ) + b ).toString( 16 ).slice( 1 ); | |
var hexToRgb = ( hex ) => [ parseInt( hex.substring( 1, 3 ), 16 ), parseInt( hex.substring( 3, 5 ), 16 ), parseInt( hex.substring( 5, 7 ), 16 ) ]; | |
rgbToHex( 175, 25, 70 ); // #af1946 | |
hexToRgb( "#af1946" ); // [ 175, 25, 70 ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment