cnVCL whether add the function to conversion floating number to hexadecimal string ?
sxbug opened this issue · comments
cnFloat could conversion from 12.5 to C.8. Can it be converted to IEEE754's 41 48 00 00.
I think this function is used a lot.
thank you!
You can use
function DataToHex(InData: Pointer; ByteLength: Integer; UseUpperCase: Boolean = True): string;
in CnNative.pas to directly convert the memory content of Float number to a hex string.
given
var
A: Single;
begin
Caption := DataToHex(@A, SizeOf(A));
end;
thanksthanks
I only found the function: #1#2#3#4 <---> '1234'.
But I want a function:12.5 <---> '41 48 00 00'
Thanks
Could you use my code piece and check the result?
var
A: Single;
begin
A := 12.5;
Result := DataToHex(@A, SizeOf(A));
end;
In above:
function DataToHex(InData: Pointer; ByteLength: Integer; UseUpperCase: Boolean = True): string;
is in cnvcl\Source\Crypto\CnNative.pas
Thank you for your guidance。
I misunderstand at first. Now I also want to know which function could convert # $41 48 00 00 to 12.5 , hex-->single。
Happy Chinese new year!
There's also a function HexToData in CnNative.pas
Note:
- Space Chars in String should be removed before calling this function.
- Notice the BigEndian/Little Endian byte order after conversion.
These compoments is very good, but there are a few documents。Thanks