http://www.dolcevie.com/js/converter.html
without the colons (maybe spaces instead)
Function BufToHexStr(N:Cardinal;Buf:pCharTab;Col:Byte=0;HexaWidth:Byte=0;CDef:Boolean=False;Indent:Byte=0):String;
Var
i:Integer;
Hdr,Ftr,NewL,IdtStr:String;
begin
if Buf=nil Then Exit;
IdtStr:=DupeString(' ',Indent);
NewL:=CRLF+IdtStr;
if CDef Then
begin
Result:='{ ';
Hdr:='0x';
Ftr:=' ,';
end Else
begin
Result:='';
Ftr:=' ';
Hdr:='';
end;
if HexaWidth>0 Then while (Col MOD HexaWidth)>0 do Dec(HexaWidth);
For i:=0 to N-1 do
begin
if (i>0) And (HexaWidth>0) And ((i Mod HexaWidth)=0) Then Result:=Result+Ftr;
if (Col>0) And (i>0) And ((i Mod Col)=0) Then
begin
Result:=Result+NewL;
if CDef Then Result:=Result+' ';
end;
Result:=Result+Hdr+HexaChar(Buf^[i]);
end;
if CDef Then Result:=Result+NewL+'}';
end;
Function HexaStrToBuf(Src:ANSIString;ThrowException:Boolean=False):ANSIString;
begin
For i:=1 to Length(Src) do
if Not (Src[i] IN ['0'..'9','A'..'F']) Then
begin
if ThrowException And Not (Src[i] In [' ',#13,#10]) Then Raise Exception.Create('Invalid Hexa character');
Text[i]:=' ';
end;
P:=1;
Result:='';
While P<=Length(Src) do if Src[P]=' ' Then Inc(P) Else
begin
Result:=Result+Char(StrToInt('$'+Trim(Copy(Src,P,2))));
Inc(P,2);
end;
end;
Function BufToHexStr(Src:ANSIString;Col:Byte=0;HexaWidth:Byte=0):ANSIString;
Var
i:Integer;
begin
Result:='';
if HexaWidth>0 Then while (Col MOD HexaWidth)>0 do Dec(HexaWidth);
For i:=0 to Length(Src)-1 do
begin
if (i>0) And (HexaWidth>0) And ((i Mod HexaWidth)=0) Then Result:=Result+' ';
if (Col>0) And (i>0) And ((i Mod Col)=0)
Then Result:=Result+#13#10;
Result:=Result+Format('%2.2x',[Byte(Src[i+1])]);
end;
end;
If you are experiencing a similar issue, please ask a related question
Title | # Comments | Views | Activity |
---|---|---|---|
Show Listview image from database (String field) | 5 | 113 | |
How to implement a row column color change using Dev Express Quantum Grid in Delphi | 3 | 56 | |
When i run adoquery my application freezes | 26 | 150 | |
tvirtualstringtree freeze when load too manny images | 10 | 52 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
13 Experts available now in Live!