|   Web Development Knowledge Base | |
| Sections : 
  RSS Feed You too, please publish your useful code snippets in any programming language : write an article ! Plateforme d'envoi de gros fichiers en ligne Dépannage site web Blog infogérance Hébergement e-mail |     
Olivier Ligny -  - 11/03/2008 - vue 10442 fois
 hex2dec() / dec2hex() JavaScript functionshex2dec(n) : convert from hexadecimal (ff) to decimal (255) dec2hex(n) : convert from decimal (255) to hexadecimal (ff)           function Hex2DecF(HexVal){ 
		SAM - 14/03/2008
	Voici les miennes (enfin ... celles que j'ai pompées) : HEX_to_DECI(n) : convertit depuis hexadecimal (ff) vers decimal (255) DECI_to_HEXn) : convertit de decimal (255) en hexadecimal (ff) function DECI_to_HEX ( num ) {  // num maxi = 255
  var x = '';
  x += "0123456789ABCDEF".charAt((num-num%16)/16)
      + "0123456789ABCDEF".charAt(num%16);
  return x;
  }
 function HEX_to_DECI ( num ) {  // valeur hexa ( A0 ou ff ou ...)
  var result = 0;
  var max = num.toString().length-1;
  for (var i=max; i>=0; i--) 
       {
       var digit = num.charAt(i).toUpperCase();
       switch(digit)
          {
          case "A": digit = 10; break;
          case "B": digit = 11; break;
          case "C": digit = 12; break;
          case "D": digit = 13; break;
          case "E": digit = 14; break;
          case "F": digit = 15; break;
          }
      result += digit * Math.pow(16, +max-i);
      }
  return result;
}exemples : - 165 -> A5 : javascript:alert(convert_DECI_to_HEX(165)) - A5 -> 165 : javascript:alert(convert_HEX_to_DECI('a5')) 
		SAM - 14/03/2008
	Mais qu'est-ce que c'est que de m'envoyer mes liens-JS en blank ? Ha! Ha! j'ai réussi à plonker l'truc là avec mon 2ième lien ;-) | 
| Nos partenaires : iPhone 8 Cases & Protection | |