如何把一个整数转化为3个十六进制字节 delphi
比如把整数149259(都是6位数据整型数) 转换为十六进制为2470B然后再分开为三个字节02 47 0B,求实现代码
示例
var
ID: Integer;
ByteBuf: array[0..2] of Byte;
begin
ID := 149259;
..........
ByteBuf[0] := //02
ByteBuf[1] := //47
ByteBuf[2] := //0B
end;
------解决思路----------------------
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;