(1) var A : Double = 3.9876;
(2) var B : Extended = 3.9876;
(3) var C : Currency = 3.9876;
(4) var D : Real = 3.9876;问题:
1、上面四个变量,在内存中各二进位是如何表示的。
2、请给出用代码查看其内存表示的方法。
(2) var B : Extended = 3.9876;
(3) var C : Currency = 3.9876;
(4) var D : Real = 3.9876;问题:
1、上面四个变量,在内存中各二进位是如何表示的。
2、请给出用代码查看其内存表示的方法。
A: Double;
B: Extended;
C: Currency;
D: Real;
I: Integer;
S, R: string;
AA: array[0..9] of Byte;
begin
Memo1.Clear;
A := 3.9876;
B := 3.9876;
C := 3.9876;
D := 3.9876;
SetLength(S, 20); FillChar(AA[0], Length(AA), 0);
FillChar(S[1], Length(S), 0);
PDouble(@AA[0])^ := A;
for I := 0 to 9 do
begin
R := IntToHex(AA[I], 2);
S[I * 2 + 1] := R[1];
S[I * 2 + 2] := R[2];
end;
Memo1.Lines.Add(S); FillChar(AA[0], Length(AA), 0);
FillChar(S[1], Length(S), 0);
PExtended(@AA[0])^ := B;
for I := 0 to 9 do
begin
R := IntToHex(AA[I], 2);
S[I * 2 + 1] := R[1];
S[I * 2 + 2] := R[2];
end;
Memo1.Lines.Add(S); FillChar(AA[0], Length(AA), 0);
FillChar(S[1], Length(S), 0);
PCurrency(@AA[0])^ := C;
for I := 0 to 9 do
begin
R := IntToHex(AA[I], 2);
S[I * 2 + 1] := R[1];
S[I * 2 + 2] := R[2];
end;
Memo1.Lines.Add(S); FillChar(AA[0], Length(AA), 0);
FillChar(S[1], Length(S), 0);
Move(D, AA[0], SizeOf(Real));
for I := 0 to 9 do
begin
R := IntToHex(AA[I], 2);
S[I * 2 + 1] := R[1];
S[I * 2 + 2] := R[2];
end;
Memo1.Lines.Add(S);
end;
http://blog.csdn.net/jsblcg/archive/2006/10/29/1355557.aspx
不过是C/C++的数据结构,希望你能看得懂