http://www.dolcevie.com/js
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;
Title | # Comments | Views | Activity |
---|---|---|---|
Delphi XE7 Rest Client | 2 | 172 | |
Strange message in Delphi 10 Seattle | 1 | 463 | |
Delphi OLE Error | 8 | 82 | |
Convert Jpg /PNG To GIF | 5 | 102 |
Join the community of 500,000 technology professionals and ask your questions.
Connect with top rated Experts
18 Experts available now in Live!