Possible Duplicate:
Converting float or negative integer to hexadecimal in Borland Delphi
Is there a function i can use to convert a floating point value to a hexadecimal value and back?
procedure ShowBinaryRepresentation;
var
S, S2: Single;
I: Integer;
D, D2: Double;
I64: Int64;
begin
S := -1.841;
I := PInteger(@S)^;
OutputWriteLine(Format('Single in binary represenation: %.8X', [I]));
S2 := PSingle(@I)^;
OutputWriteLine(Format('Converted back to single: %f', [S2]));
D := -1.841E50;
I64 := PInt64(@D)^;
OutputWriteLine(Format('Double in binary represenation: %.16X', [I64]));
D2 := PDouble(@I64)^;
OutputWriteLine(Format('Converted back to double: %f', [D2]));
end;
Single in binary represenation: BFEBA5E3 Converted back to single: -1,84 Double in binary represenation: CA5F7DD860D57D4D Converted back to double: -1,841E50
Not floating point. There is inttohex to change integers (maybe int64 too) to hex strings.
Probably you need to pry apart the bits in the IEEE format double type and change them to hex which you then concat with a point inbetween.
If this is not the answer you are looking for, please specify what you mean by "hexadecimal value".
If you just want to convert it to an array of e.g. bytes, define a array of byte type with a suitable size (4 for single, 8 for double and 10 extended), and typecast.
精彩评论