浏览代码

Libraries: added buffer2hex common function

Herman Schoenfeld 7 年之前
父节点
当前提交
e560bf5945
共有 1 个文件被更改,包括 17 次插入0 次删除
  1. 17 0
      src/libraries/sphere10/UCommon.pas

+ 17 - 0
src/libraries/sphere10/UCommon.pas

@@ -39,6 +39,7 @@ const
 
 { Converts a string to hexidecimal format }
 function String2Hex(const Buffer: AnsiString): AnsiString;
+function Buffer2Hex(const ABuffer: TBytes) : AnsiString;
 
 { Binary-safe StrComp replacement. StrComp will return 0 for when str1 and str2 both start with NUL character. }
 function BinStrComp(const Str1, Str2 : AnsiString): Integer;
@@ -356,6 +357,22 @@ begin
     Result := LowerCase(Result + IntToHex(Ord(Buffer[n]), 2));
 end;
 
+
+function Buffer2Hex(const ABuffer: TBytes) : AnsiString;
+var
+  i : Integer;
+  s : AnsiString;
+  b : Byte;
+begin
+  System.SetLength(Result, System.Length(ABuffer)*2);
+  for i := 0 to System.Length( ABuffer ) - 1 do begin
+    b := Ord(ABuffer[i+1]);
+    s := IntToHex(b,2);
+    Result[(i*2)+1] := s[1];
+    Result[(i*2)+2] := s[2];
+  end;
+end;
+
 function BinStrComp(const Str1, Str2: AnsiString): integer;
 var Str1Len, Str2Len, i : Integer;
 begin