Home > Back-end >  Four hexadecimal converts floating-point, how to do
Four hexadecimal converts floating-point, how to do

Time:09-25

Four hexadecimal converts floating-point, how to implement the
Single-chip microcomputer the data returned is: 43 B6 D9 9 a four hexadecimal
Converted to floating point is: 365.7
For help how to implement, it is best to post code, thank you

CodePudding user response:

Should more than these four, according to the size of the different, still should have 00 00 00 00 before, during, and after it

CodePudding user response:

Single precision floating point is 4 bytes, double-precision floating-point just as upstairs say around 4 00, upstairs a little said is right, pay attention to the big end small side problem, the most simple transformation method is to use a pointer, the example code is as follows,

 var 
Data: the Cardinal;
Pf: PSingle;
The begin
Data:=$43 b6d99a;
Pf:=@ data;
ShowMessage (FloatToStr (pf ^));
end;

CodePudding user response:

Delphi support absolute addresses, can be directly:
Var
Data: the Cardinal;
F: Single absolute data;
The begin
Data:=$43 b6d99a;
ShowMessage (Format (' % 8.2 f, [f]));
end;

CodePudding user response:

 function HextoFloat (s: string) : real; 
Var b, temp: string;
E: integer;
F: real;
The begin
B:=HextoBinary (s);
Temp:=copy (b, 2, 8);
E:=BintoInt (temp) - 127;
Temp:=copy (b, 10, 10);
F:=1 + floatBintoInt (temp);
If (copy (b, 1, 1)='0') then
Result:=power (2 e) * f
The else
Result:=- power (2 e) * f;
end;

CodePudding user response:

Can also use a composite structure, more intuitive,
SCM generally use single precision floating point, pay attention to the high and low byte, int in front of the computer is the low byte in
//single-precision floating-point said
TSingleRecord=record
In case the Integer of
0: (bLL, bLH, bHL, bHH: Byte);//low byte before
1: (wl, wh: Word);//low word before
Value: 2: (Single);//floating-point
end;
  • Related