DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

HEX To RGB

04.21.2005
| 13498 views |
  • submit to reddit
        
function hexToRGB ( hex:Number ){
   var returnObj:Object = new Object();   
   var returnObj .r = hex >> 16;
   var temp = hex ^ r << 16;
   var returnObj .g = temp >> 8;
   var returnObj .b = temp ^ g << 8;

   return returnObj;
}
    

Comments

Snippets Manager replied on Sat, 2007/11/17 - 4:05pm

function hex2RGB ( hex:Number ) { var rgb:Object = { r:Number = (hex & 0xff0000) >> 16, g:Number = (hex & 0x00ff00) >> 8, b:Number = hex & 0x0000ff } return rgb; } function RGB2hex ( rgb:Object ) { return (rgb.r << 16) + (rgb.g << 8) + rgb.b; }