5,392
社区成员
发帖
与我相关
我的任务
分享
function AscToBin(instr: PAnsiChar; inlen: Integer; outstr: PByte): Integer;
var
i: Integer;
c: AnsiChar;
h: Byte;
l: Byte;
begin
for i := 0 to (inlen div 2) - 1 do
begin
c := instr^;
if c in ['0'..'9'] then h := Byte(c) - $30;
if c in ['A'..'F'] then h := Byte(c) - $41 + $0A;
if c in ['a'..'f'] then h := Byte(c) - $61 + $0A;
c := (instr + 1)^;
if c in ['0'..'9'] then l := Byte(c) - $30;
if c in ['A'..'F'] then l := Byte(c) - $41 + $0A;
if c in ['a'..'f'] then l := Byte(c) - $61 + $0A;
outstr^ := (h shl 4) + l;
Inc(instr, 2);
Inc(outstr, 1);
end;
Result := inlen div 2;
end;
function TForm1.DelphiAscToBin(instr:array of Byte;inlen:Integer;outstr:array of Byte):Integer;
var
i:Integer;
c,high,low:Byte;
begin
for i:=0 to inlen div 2 do
begin
c:=instr[i];
if not ( Chr(c) in ['0'..'9']) then
high:=c-$30;
//下面的你自己换下 同理可得
end;
end;