在Delphi中Integer占用4个字节,现在怎么把一个Integer转换为长度为4的byte[] ?
http://topic.csdn.net/u/20100126/14/6D1DAB33-07FF-412B-B0F9-FC127AA9261A.html
我的问题是Double在Delphi中是否是8字节,应该是吧。怎么把一个Double转换为长度为8的byte[] 呢 ?谢谢大家~
http://topic.csdn.net/u/20100126/14/6D1DAB33-07FF-412B-B0F9-FC127AA9261A.html
我的问题是Double在Delphi中是否是8字节,应该是吧。怎么把一个Double转换为长度为8的byte[] 呢 ?谢谢大家~
b : array of Byte;
n1,n2: Cardinal;
begin
SetLength(b,8); n1 := Int64Rec(Value).Lo;
n2 := Int64Rec(Value).Hi;
b[0] := (n2 and $ff000000) shr 24;
b[1] := (n2 and $00ff0000) shr 16;
b[2] := (n2 and $0000ff00) shr 8;
b[3] := n2 and $000000ff;
b[4] := (n1 and $ff000000) shr 24;
b[5] := (n1 and $00ff0000) shr 16;
b[6] := (n1 and $0000ff00) shr 8;
b[7] := n1 and $000000ff;
我这样做的,,但是结果不对啊
procedure TForm1.Button1Click(Sender: TObject);
var
byte1,byte2:Byte;
dv:Double;
begin
byte1:=1;
byte2:=1;
dv:=byte1* $100 +byte2;
Caption:=FloatToStr(dv)
end;
谢谢,不过我没看懂~
我说的是要把已有的Double Value 转换成byte[8] 的功能
b:array [0..7] of byte;copy(dblvar,b[0],8);
var
a: array[0..7] of Byte;
d1, d2: Double;
begin
d1 := 123.456;
fillchar(a, 8, 0);
Move(d1, a, 8);
Move(a, d2, 8);
ShowMessage(FloatToStr(d2));
end;
sz_haitao 说的是
Var
b:array[0..7] of byte;
//Value是Integer
Copy(b,Value,8); 这个意思吗?但是 不对啊
//做类型强制转换即可
procedure TForm1.btn1Click(Sender: TObject);
var
bs: PByteArray;
num: double;
begin
num := 1;
bs := @num;
end;
就决定了
b[i]最大就是FF,不管你拿多大的值赋给它,它自动截取8位,FF不就是11111111吗?你所说的长度为8的byte是什么意思呢?
procedure Move(const Source; var Dest; Count: Integer);
//Value是double
move(Value,b[0],8);
move(b,Value,8);