Last active
October 9, 2016 00:18
-
-
Save UweRaabe/5519464bd5ef18c3d887bc784ddaa034 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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