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 : 72998
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...

{Visual Basic, VB6, VB.NET, VB 2005} CONVERTIR UN MOT EN UNICODE (N'ACCEPTANT PAS LES CARACTÈRES ACCENTUÉS) EN UN STRING (AVEC LES ACCENTS)
Salut, C'est mon premier code et je l'ai fait car j'ai tant recherché ce genre de code sans résulta...

{Visual Basic, VB6, VB.NET, VB 2005} CONVERTIR_COMPRESSER_TIF
Convertir et compresser des fichiers JPEG et BMP en TIF. Image par image ou par lot.Vous pouvez voir...

{Visual Basic, VB6, VB.NET, VB 2005} CREER_MULTIPAGE_TIF
Créer un fichier multipage Tif de 2 ou 3 images, en VB.Net et VBA Excel. Avec Microsoft Windows Imag...

{JAVA / J2EE} STRING TO (STRING) HEXA
Rien de bien méchant, mais c'est toujours utile de pouvoir avoir la valeur des caractères d'un strin...

{C / C++ / C++.NET} CONVERTISSEUR NOMBRE ARABE EN NOMBRE ROMAIN
voici un petit programme qui transcris un nombre arabe en nombre romain. explications : on vér...

{PHP} CHIFFRES EN LETTRES
cette source converti des chiffres en des chaines de caractère en toute lettre supporte jusqu'à 999...

{Delphi} CONVERTISSEUR D'UN NOMBRE DÉCIMAL EN BINAIRE ET HEXADECIMAL
Petit programme très simple qui convertit un nombre décimal que l'utilisateur saisi lui-même en nomb...