Please login or register. Welcome to the Studio, guest!


Quick Links:


newBookmarkLockedFalling

Eric

Eric Avatar



1,442


November 2005
No clue what you'd use this for, but meh:
var hex = '0123456789ABCDEF';
function d2h(num)
{
   var newHex = '';
   while(num != 0)
   {
      newHex = hexcharAt(num % 16) + newHex;
      num = Math.floor(num / 16);
   }
   return newHex;
}
function h2d(hexnum)
{
   hexnum = hexnum.toString();
   if(hexnum.match(/[0-9A-Z]/i))
   {
      hexnum = hexnum.toUpperCase();
      var end = 0;
      for(var x = 0; x < hexnum.length; x++)
      {
         end += hex.indexOf(hexnum.charAt(x)) * Math.pow(16, hexnum.length - 1 - x);
      }
      return end;
   }else{
      alert("The hexadecimal number can only contain numbers 0 through 9 and letters A through F");
      return 0;
   }
}


This is actual hex, not RGB hex.


Last Edit: Nov 6, 2005 4:59:58 GMT by Eric

newBookmarkLockedFalling