Converting float or negative integer to hexadecimal in Borland Delphi

前端 未结 4 2095
南旧
南旧 2021-01-23 22:51

Ive written a program that communicate with some hardware using a serial connection. It sends a lot of hexadecimal values my way (sensor readings) and every once in a while it s

4条回答
  •  逝去的感伤
    2021-01-23 23:13

    to convert a hex string into a integer, you can use the StrToInt Function , also you can check the TryStrToInt function (wich returns False if string does not represent a valid number).

    uses
    SysUtils;
    
    var
    ivalue : integer;
    begin
    ivalue:=StrToInt('$FFFFF5D6'); // Hexadecimal values start with a '$' in Delphi
    
    ..
    end;
    

    For the Hexadecimal representation of a float number, you can check theses articles.

    • http://www.merlyn.demon.co.uk/pas-type.htm#Str
    • http://www.merlyn.demon.co.uk/pas-real.htm
    • http://www.merlyn.demon.co.uk/programs/hexfloat.pas (source code example)

提交回复
热议问题