Fonction BintoHex

bronx84 Messages postés 6 Date d'inscription mardi 18 octobre 2005 Statut Membre Dernière intervention 27 mars 2007 - 8 nov. 2005 à 10:14
f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 - 9 nov. 2005 à 06:41
Bonjour,



Je ne comprend pas comment je dois utiliser la fonction BinToHex, pourriez-vous m'aider, s'il vous plaît.

1 réponse

f0xi Messages postés 4205 Date d'inscription samedi 16 octobre 2004 Statut Modérateur Dernière intervention 12 mars 2022 35
9 nov. 2005 à 06:41
var

// une variable de type Integer

valL : integer; (32bits signed long)

// une autre de type Float

valS : single; (32bits signed float)

// un tableau pour les Integer

bufL : array[0..SizeOf( integer ) * 2] of Char;

// un tableau pour les Float, soit 4 octets*2

bufS : array[0..SizeOf( single ) * 2] of Char;



begin

// on initialise avec des valeurs de tests

valL := 7892456;

valS := 3.14159;



// on convertis dans les Tableaux

BinToHex(@valL, bufL, SizeOf(valL));

BinToHex(@valS, bufS, SizeOf(valS));



// on supprime le dernier caractere pour un affichage propre

bufL[SizeOf(bufL) - 1] := #0;

bufS[SizeOf(bufS) - 1] := #0;



// on retourne le resultat grace a Format

label1.caption :format('%d %s en hexa',[valL,bufL]);

label2.caption :format('%f %s en hexa',[valS,bufS]);

end;





pour faciliter le tout on pourrait ecrire une fonction simple qui faciliterais grandement la chose :



function IntToHex(const INT : integer) : string;

var BufInt : array[0..SizeOf( integer ) * 2] of Char;

begin

BinToHex(@INT, BufInt, SizeOf(INT));

BufInt[SizeOf(BufInt) - 1] := #0;

result := format('%s',[BufInt]);

end;
0
Rejoignez-nous