Convertir Binary -> Hexadecimal  

Send By: Q3 Team
Web : http://www.q3.nu
Email: dlib@q3.nu
Date: 07/08/99

Tip accessed 536 times

 



 function BinToHex(Binario:string):string;
 const
      BCD: array [0..15] of string=
        ('0000','0001','0010','0011','0100','0101','0110','0111',
         '1000','1001','1010','1011','1100','1101','1110','1111');
      HEX: array [0..15] of char=
        ('0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F');
 var
    i,n:integer;
    sTemp:string;
    sNibble:string;
 begin
    Result:='';
    sTemp:=Binario+Copy('000',1,Length(Binario) mod 4);
    for i:=0 to (Length(Binario) shr 2)-1 do
    begin
     sNibble:=Copy(sTemp,(i shl 2)+1,4);
     n:=8;
     while (sNibble <> BCD[n]) do
       if sNibble < BCD[n] then Dec(n) else Inc(n);
     Result:=Result+HEX[n];
    end;
 end;



A call example:


   Label1.Caption:=BintoHex('100011100100101011');