Skip to content

Instantly share code, notes, and snippets.

@jakebellacera
Created May 4, 2012 05:04
Show Gist options
  • Save jakebellacera/2592162 to your computer and use it in GitHub Desktop.
Save jakebellacera/2592162 to your computer and use it in GitHub Desktop.
RGB to Hex
/*----------------------------------------------------------
RGB to HEX Converter
----------------------------------------------------------*/
var hex = {
temp: {
chars: '0123456789ABCDEF',
partA: '',
partB: '',
output: ''
},
generate: function(){
this.temp.output = ''; // Cleanup
for( var i = 0; i < arguments.length; i++ ) {
partA = this.temp.chars.charAt( Math.floor( arguments[i] / 16 ) );
partB = this.temp.chars.charAt( Math.floor( arguments[i] - ( Math.floor( arguments[i] / 16 ) * 16 ) ) );
this.temp.output += partA + partB;
}
return '#' + this.temp.output;
}
};
hex.generate(255,255,255); // #FFFFFF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment