[求助]二进制转字符串
我要从串口读如一行数据:00 35 45 45,但我读数的函数是字符串格式的,delphi单元有没有包含什么函数是可以互相转换的?
function HexToBuffer(const Hex : string; var Buf; BufSize : Cardinal) : Boolean;
var
i, C : Integer;
Str : string;
Count : Integer;
begin
Result := False;
Str := '';
for i := 1 to Length(Hex) do
if Upcase(Hex[i]) in ['0'..'9', 'A'..'F'] then
Str := Str + Hex[i];
FillChar(Buf, BufSize, #0);
Count := Min(Length(Hex), BufSize);
for i := 0 to Count - 1 do begin
Val('$' + Copy(Str, (i shl 1) + 1, 2), TByteArray(Buf)[i], C); {!!.01}
if (C <> 0) then
Exit;
end;
Result := True;
end;
TruboPower 里面抄个函数给你。