Skip to content

Instantly share code, notes, and snippets.

View jeffreyyoung's full-sized avatar
💭
🐬🐬🐬🐬🐬🐬🐬🐬🐬

Jeffrey Young jeffreyyoung

💭
🐬🐬🐬🐬🐬🐬🐬🐬🐬
View GitHub Profile
@lrvick
lrvick / bitcolor.js
Created March 18, 2012 20:02
Javascript functions for doing fast binary/hex/RGB color conversions using bitwise operations.
// convert 0..255 R,G,B values to binary string
RGBToBin = function(r,g,b){
var bin = r << 16 | g << 8 | b;
return (function(h){
return new Array(25-h.length).join("0")+h
})(bin.toString(2))
}
// convert 0..255 R,G,B values to a hexidecimal color string
RGBToHex = function(r,g,b){