Собственно пару функций для конвертера форматов (d4 & fpc), добавьте если нужно (для передачи по COM порту вероятно точно нужно)
Проверить можно тут http://www.binaryconvert.com/convert_double.html
Код:
Add(MainForm,2953706,28,161) { Width=450 Height=156 } Add(InlineCode,10978967,154,119) { WorkPoints=#13:doDoubleToHex|13:doHexToDouble|0:| EventPoints=#5:onHex|6:onReal| Code=#15:unit HiAsmUnit;|0:|9:interface|0:|21:uses kol,Share,Debug;|0:|4:type|28: THiAsmClass = class(TDebug)|10: private|0:|9: public|29: onHex,onReal: THI_Event;|55: procedure doHexToDouble(var dt: TData; idx: word);|55: procedure doDoubleToHex(var dt: TData; idx: word);|5: end;|1: |49: function HexToDouble(const hex: string): Double;|47: function DoubleToHex(const d: Double): string;|0:|14:implementation|0:|36:procedure THiAsmClass.doHexToDouble;|5:begin|49: _hi_OnEvent(onReal, HexToDouble(ToString(dt)));|4:end;|0:|36:procedure THiAsmClass.doDoubleToHex;|5:begin|46: _hi_OnEvent(onHex, DoubleToHex(ToReal(dt)));|4:end;|0:|48:function HexToDouble(const hex: string): Double;|3:var|12: d: Double;|45: Overlay: array[1..2] of LongInt absolute d;|5:begin|29: if LENGTH(hex) <> 16 then |49: _Debug('Invalid hex string for HexToDouble');|72: // then raise EIEEEMath.Create('Invalid hex string for HexToDouble');|42: Overlay[1] := cHex2Int(COPY(hex, 9, 8));|42: Overlay[2] := cHex2Int(Copy(hex, 1, 8));|14: Result := d;|4:end;|0:|46:function DoubleToHex(const d: Double): string;|3:var|45: Overlay: array[1..2] of LongInt absolute d;|5:begin|73: // Look at element 2 before element 1 because of "Little Endian" order.|60: Result := Int2Hex(Overlay[2], 8) + Int2Hex(Overlay[1], 8);|5:end; |1: |4:end.| link(onHex,15426071:doText,[]) link(onReal,5127712:doText,[(222,132)(222,174)]) } Add(Edit,3844880,84,63) { Left=15 Top=20 Text="1.7" } Add(Button,9185643,28,119) { Left=80 Top=20 Width=85 Caption="RealToHex" link(onClick,4444644:doData,[]) } Add(Edit,15426071,245,119) { Left=190 Top=20 Width=225 Text="" } Add(DoData,4444644,84,119) { link(onEventData,10978967:doDoubleToHex,[]) link(Data,3844880:Text,[]) } Add(Edit,9926444,84,161) { Left=15 Top=60 Width=235 Text="3FF0000000000000" } Add(Button,5509348,28,210) { Left=265 Top=60 Width=85 Caption="HexToReal" link(onClick,13471617:doData,[]) } Add(Edit,5127712,245,168) { Left=365 Top=60 Text="" } Add(DoData,13471617,84,210) { link(onEventData,10978967:doHexToDouble,[(135,216)(135,132)]) link(Data,9926444:Text,[]) } Add(PointHint,5186153,35,14) { Info=#65:для проверки - http://www.binaryconvert.com/convert_double.html| Font=[MS Sans Serif,8,1,8388608,1] Width=456 }