s := '0090C2FF0003'; for i:=1 to Length(s) DIV 2 do FramBuf[i DIV 2] := StrToInt('$' + Copy(s,i*2-1, 2) );
var i, len: integer; s: string; FramBuf:array[0..5] of byte; begin s := '0090C2FF0003'; for i := (length(s) div 2) downto 1 do begin showMessage(s[i*2-1] + s[i*2]); FramBuf[i] := StrToInt(s[i*2-1] + s[i*2]); end; end;
HexToBin绝对可以,效率也最高//自己查帮助,看vcl源码,Borland早已考虑 function HexToBin(Text, Buffer: PChar; BufSize: Integer): Integer; const Convert: array['0'..'f'] of SmallInt = ( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1, -1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, -1,10,11,12,13,14,15); var I: Integer; begin I := BufSize; while I > 0 do begin if not (Text[0] in ['0'..'f']) or not (Text[1] in ['0'..'f']) then Break; Buffer[0] := Char((Convert[Text[0]] shl 4) + Convert[Text[1]]); Inc(Buffer); Inc(Text, 2); Dec(I); end; Result := BufSize - I; end;
for i:=1 to Length(s) DIV 2 do
FramBuf[i DIV 2] := StrToInt('$' + Copy(s,i*2-1, 2) );
s: string; FramBuf:array[0..5] of byte;
begin
s := '0090C2FF0003';
for i := (length(s) div 2) downto 1 do
begin
showMessage(s[i*2-1] + s[i*2]);
FramBuf[i] := StrToInt(s[i*2-1] + s[i*2]);
end;
end;
function HexToBin(Text, Buffer: PChar; BufSize: Integer): Integer;
const
Convert: array['0'..'f'] of SmallInt =
( 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,-1,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
-1,10,11,12,13,14,15);
var
I: Integer;
begin
I := BufSize;
while I > 0 do
begin
if not (Text[0] in ['0'..'f']) or not (Text[1] in ['0'..'f']) then Break;
Buffer[0] := Char((Convert[Text[0]] shl 4) + Convert[Text[1]]);
Inc(Buffer);
Inc(Text, 2);
Dec(I);
end;
Result := BufSize - I;
end;