From the "Format strings" help topic:
x Hexadecimal. The argument must be an integer value. The value is
converted to a string of hexadecimal digits. If the format string contains a
precision specifier, it indicates that the resulting string must contain at
least the specified number of digits; if the value has fewer digits, the
resulting string is left-padded with zeros.
procedure TForm1.Button1Click(Sender: TObject);
var T1, T2 : Int64;
T3 : Int64;
begin
T1 := $0FFFFFFF;
T2 := $FFFFFFFF;
T3 := (T1 shl 32) or T2;
Edit1.Text := Format('%.20x', [T3]);
Edit2.Text := IntToStr(T3);
end;
Strangely, using '%20x' left-pads the string with _spaces_.
--David
>Strangely, using '%20x' left-pads the string with _spaces_.
IntToHex does the same thing. I fear this is a new "feature" of Delphi 4
instead of a bug.
Here's the problem I was having (trying to keep leading zeros in some hex
constants, which is important when dealing with floating point numbers in
hex):
// Delphi 3 routine
FUNCTION DoubleToHex(CONST d: DOUBLE): STRING;
VAR
Overlay: ARRAY[1..2] OF LongInt ABSOLUTE d;
BEGIN
// Look at element 2 before element 1 because
// of "Little Endian" order.
RESULT := IntToHex(Overlay[2],8) + IntToHex(Overlay[1],8);
END {DoubleToHex};
Seemingly, this routine could have been simplified in Delphi 4 to the
following, but IntToHex works slightly differently with Int64 values.
IntToHex now suppresses leading 0s in the hex string, so the above Delphi 3
code still works best .
// Delphi 4 code suppresses leading 0s in hex strings below. Why?
FUNCTION DoubleToHex(CONST d: DOUBLE): STRING;
VAR
Overlay: Int64 ABSOLUTE d;
BEGIN
RESULT := IntToHex(Overlay, 16)
END {DoubleToHex};
efg
_________________________________________
efg's Computer Lab: http://infomaster.net/external/efg
Earl F. Glynn E-Mail: Earl...@att.net
MedTech Research Corporation, Lenexa, KS USA
http://www.dataweb.net/~r.p.sterkenburg/generated/rtlunits.htm#SysUtils.Format