Skip to content

Instantly share code, notes, and snippets.

@UweRaabe
Last active October 9, 2016 00:18
Show Gist options
  • Save UweRaabe/5519464bd5ef18c3d887bc784ddaa034 to your computer and use it in GitHub Desktop.
Save UweRaabe/5519464bd5ef18c3d887bc784ddaa034 to your computer and use it in GitHub Desktop.
function BytesToHex(const ASource: TBytes): string;
var
target: TBytes;
begin
SetLength(target, Length(ASource)*2);
BinToHex(ASource, 0, target, 0, Length(ASource));
result := TEncoding.ANSI.GetString(target);
end;
function StringToHex(const ASource: string; AEncoding: TEncoding): string;
begin
result := BytesToHex(AEncoding.GetBytes(ASource));
end;
function SeparateString(const ASource, ASeparator: string; AChunkLength: Integer): string;
var
I: Integer;
begin
result := ASource;
for I := Pred(result.Length) div AChunkLength downto 1 do begin
Insert(ASeparator, result, I*AChunkLength + 1);
end;
end;
function UniLE2HexStr(const s_in: string): String;
begin
result := SeparateString(StringToHex(s_in, TEncoding.Unicode), ',', 2);
end;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment