Mega Code Archive

 
Categories / Delphi / Algorithm Math
 

Hextobin,hextoint and more

//drony@mynet.com //icq:266148308 //hex to binary procedure TForm1.Button1Click(Sender: TObject); function HextoBin(Hexadecimal: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'); var i:integer; begin for i:=Length(Hexadecimal) downto 1 do Result:=BCD[StrToInt('$'+Hexadecimal[i])]+Result; end; begin Label1.Caption:=HextoBin('FA34345C2344BED'); end; -------------------------------------------------------------------------------- //hex to integer procedure TForm1.Button2Click(Sender: TObject); function HexToInt(const Value: String): Integer; begin Result := StrToInt('$' + Value); end; begin Label1.Caption:=IntToStr( HexToInt('ff') ); end; -------------------------------------------------------------------------------- //integer to hexadecimal button1.Caption := IntToHex(StrToInt64(label1.Caption), 6); --------------------------------------------------------------------------------