Integer转Bte方法

来源:互联网 发布:非常勿扰软件 编辑:程序博客网 时间:2024/05/21 03:23

i:integer;

b:array[0..3] of byte;

 

1. b[0]=byte(i)

 

2.byte[0]:=(i and $ff000000) shr 24);
byte[1]:=(i and $00ff0000) shr 16);
byte[2]:=(i and $0000ff00) shr 8);
byte[3]:=i and $000000ff; 
 

3.move(i,buf[0],4);

4.Type
  PbyteAry=^TbyteAry;
  TbyteAry=Array[0..3] of byte;
var b:TbyteAry;
    i:integer;
begin
  i:=1000;
  //方法1
  move(i,b,SizeOf(TbyteAry));
  //方法2
  b:=PbyteAry(@i)^;
end;

原创粉丝点击