var ID: Integer; ByteBuf: array[0..2] of Byte; begin ID := 149259; Move(id,ByteBuf[0],3); //字节顺序会与你的要求相反 end;
var ID: Integer; ByteBuf: array[0..2] of Byte; begin ID := 149259; ByteBuf[0] := (ID and $FF0000) shr 16; ByteBuf[1] := (ID and $00FF00) shr 8; ByteBuf[2] := ID and $0000FF; end;
var ID: Integer; ByteBuf: array [0..3] of Byte absolute ID; begin ID := 149259; end;absolute关键字会给ByteBuf分配与ID相同的地址空间。给ID赋值,直接从ByteBuf中读取就可以了。不过这个与计算机的字长和字节顺序有一定关系,具体能读出什么值来要试一下。
var s:string; len:Integer; AData:TBytes; begin s:=IntToHex(149259,6);//返回6位字符串 len := length(s) div 2; Setlength(AData,len); HextoBin(pchar(s),@AData[0],len); end;这个应该适合你用。
var
ID: Integer;
ByteBuf: array[0..2] of Byte;
begin
ID := 149259;
Move(id,ByteBuf[0],3); //字节顺序会与你的要求相反
end;
ID: Integer;
ByteBuf: array[0..2] of Byte;
begin
ID := 149259;
ByteBuf[0] := (ID and $FF0000) shr 16;
ByteBuf[1] := (ID and $00FF00) shr 8;
ByteBuf[2] := ID and $0000FF;
end;
ID: Integer;
ByteBuf: array [0..3] of Byte absolute ID;
begin
ID := 149259;
end;absolute关键字会给ByteBuf分配与ID相同的地址空间。给ID赋值,直接从ByteBuf中读取就可以了。不过这个与计算机的字长和字节顺序有一定关系,具体能读出什么值来要试一下。
s:string;
len:Integer;
AData:TBytes;
begin
s:=IntToHex(149259,6);//返回6位字符串
len := length(s) div 2;
Setlength(AData,len);
HextoBin(pchar(s),@AData[0],len);
end;这个应该适合你用。