Les Snippets

Connexion

Conversion Hexadécimal -> Décimal

Niveau requis pour utiliser/comprendre cette source : 1 ( Débutant )
Créé le 22/04/2006 19:59:48 et initié par Willi [Liste]
Date de mise à jour : 27/07/2007 18:09:27
Vue : 59990
Catégorie(s) : Chaîne de caractères, Divers
Langages dispo pour ce code :
- VB6, VBA
- VB 2005, VB.NET 1.x
- PHP 3, PHP 4, PHP 5
- C# 1.x, C# 2.x
- Java
- C++
- Delphi 5
- C
- Windev
- Python
- CamlLight
- Perl



Langage : VB6 , VBA
Date ajout : 22/04/2006
Posté par Willi [Liste]
DateMAJ : 13/03/2007
Function HexaToDec(ValHex As String) As Long
  HexaToDec = Val("&H" & ValHex & "&")
End Function 
Langage : VB.NET 1.x , VB 2005
Date ajout : 23/04/2006
Posté par FREMYCOMPANY [Liste]
DateMAJ : 13/03/2007
Public Module _Nbr
   Public Function HexaToDec(ValHex As String) As Integer
      Return Val("&H" & ValHex & "&")
   End Function
   Public Function DecToHexa(ValDec as Integer) As String
      Return Hex(ValDec)
   End Function
End Module
Langage : PHP 3 , PHP 4 , PHP 5
Date ajout : 24/04/2006
Posté par malalam [Liste]
<?php
$numberDec = hexdec ($sHexa); 
?>
Langage : C# 1.x , C# 2.x
Date ajout : 27/04/2006
Posté par Bidou [Liste]
DateMAJ : 12/08/2006

// Hexadecimal to Decimal
public static int HexToDec(string hexValue) 
{
   return Int32.Parse(hexValue, System.Globalization.NumberStyles.HexNumber); 
}

// Decimal to Hexadecimal
public static string DecToHex(int decValue) 
{
   return string.Format("{0:x}", decValue); 
}

// Utilisation
string hex = DecToHex(15); 
int dec = HexToDec("f");







Langage : Java
Date ajout : 12/07/2006
Posté par Twinuts [Liste]
int n = Integer.parseInt("FF", 16);
System.out.println(n);
Langage : C++
Date ajout : 12/07/2006
Posté par Twinuts [Liste]
#include <iostream>
#include <string>
#include <sstream>
std::string s = "FF";
std::istringstream iss(s.c_str()); 
unsigned int x;
iss >> hex >> x;
std::cout << x;

Langage : Delphi 5
Date ajout : 05/08/2006
Posté par f0xi [Liste]
DateMAJ : 14/03/2007
I := StrToInt('$1A2B3C4D');
ou
I64 := StrToInt64('$1A2B3C4D5E6F');


Langage : C
Date ajout : 10/08/2006
Posté par BruNews [Liste]
DateMAJ : 27/07/2007
DWORD __stdcall HexaToDecimal(const char* pszHexa)
{
  DWORD ret = 0, t = 0, n = 8, c;
  while(c = *pszHexa) {
    if((c >= '0') && (c <= '9')) t = (c - '0');
    else if((c >= 'A') && (c <= 'F')) t = (c - 'A' + 10);
    else if((c >= 'a') && (c <= 'f')) t = (c - 'a' + 10);
    else break;
    ret *= 16; ret += t;
    pszHexa++;
    if(--n == 0) break;
  }
  return ret;
}

Langage : Windev
Date ajout : 11/05/2007
Posté par drcharly93 [Liste]
PROCEDURE HexaToDec( ValHex )
 RENVOYER Val( NumeriqueVersChaine( ValHex, "8d" )
PROCEDURE DecToHexa ( ValNumerique )
 RENVOYER NumeriqueVersChaine( ValNumerique, "x" )

Langage : Python
Date ajout : 19/12/2007
Posté par 0x586e [Liste]
# Decimal à hexadecimal
dh = lambda d: '%X' % d
# Hexadecimal à Decimal
hd = lambda h: int(h,16)

Remarque :
Utilisation:
print hd('0xFF')
affiche : 255
Langage : CamlLight
Date ajout : 28/04/2008
Posté par gc22 [Liste]
let rec hex_of_int n=
    let x=n mod 16
    and r=n/16
    in let prec=(
       if r=0 then ""
       else hex_of_int (n/16))
    in prec^
    (match x with
           10 ->  "A"
          |11->  "B"
          |12->  "C"
          |13->  "D"
          |14->  "E"
          |15->  "F"
          |nb-> string_of_int nb)
;;
hex_of_int 15;;(* string : F *)
let rec int_of_hex h=
    let len=string_length h
    in if len > 0
    then
        let x=h.[0]
        and m=int_of_hex (sub_string h 1 (len-1))
        in (match x with
             `A` -> 10
             |`B`-> 11
             |`C`-> 12
             |`D`-> 13
             |`E`-> 14
             |`F`-> 15
             | c -> int_of_char c)
        + m*16
    else 0
;;
int_of_hex "FF";;(* int : 255 *)

Langage : Perl
Date ajout : 04/09/2008
Posté par leknarf [Liste]
hex("deadbeef") # donne 3735928559

Remarque :
voir http://perldoc.perl.org/functions/hex.html

Snippets en rapport avec : Convertir, Base 10, Base 16, Hexa, Decimal



Codes sources en rapport avec : Convertir, Base 10, Base 16, Hexa, Decimal

{Visual Basic, VB6, VB.NET, VB 2005} CALCULATRICE DEC/HEXA AVEC PAPIER VIRTUEL
Ceci est le enieme calculatrice. Elle sort le resultat en Decimal et en Hexa en meme temps sur 2 aff...

{Visual Basic, VB6, VB.NET, VB 2005} VISUALISATION FAÇON DUMP DE TOUT FICHIER, EN HEXA OU EN DÉCIMAL.
Le but est d'analyser les octets de tout fichier pour en connaître la constitution, ou vérifier une ...

{Visual Basic, VB6, VB.NET, VB 2005} CONVERTIR UNE COULEUR HEXA HTML EN DECIMAL VB (LA VRAI FONCTION)
suite aux conneries que j'ai vu sur ce site genre Public Function InvHex(ValHex As String) As Str...

{Flash} COLORMANAGER AS3
Je partage cette classe que j'ai créée pour m'aider dans des projets nécessitant de travailler avec ...

{PHP} CONVERTIR LES RÉFÉRENCES DE COLONNE EXCEL DE CHIFFRE EN LETTRE
J'ai eu besoin de créer des tableau à l'aide de classes spécifique qui ne travaillaient qu'avec les ...

{C / C++ / C++.NET} CONVERTIR FLV 2 MP3
Tout est dit dans le titre, c'est une classe qui permet de récupérer un mp3 d'un flv. Je précise qu...

{C / C++ / C++.NET} ENCODAGE / DETECTION : UTF-8, UTF-16, ASCII, ISO 8859-1, 8859-15
Petit programme multiplateforme, basé sous Qt 4.4.1 pour la version 1 et Qt 4.3 pour la version 2 no...

{Visual Basic, VB6, VB.NET, VB 2005} BMP VERS ICO
Je voulais quelque chose de très simple, juste pour créer un fichier ICO à partir d'un BMP 32x32, 16...

{PHP} CONVERTISEUR BINAIRE OCTAL DEC HEX...
Grâce à cet outil vous allez pouvoir convertir plus rappidement vos code en binaire, octal, decimal,...

{SQL} CONVERSION DE NOMBRE EN LETTRES (SQL)
Je me suis inspiré du code c# trouvé ici (http://files.codes-sources.com/fichier.aspx?id=21491&f=con...