Convert the four byte values to the ieee754 standard floating point number.

Source: Internet
Author: User

Data in the ieee754 format is often used at work. The data in ieee754 format occupies four bytes, as if the Motorola format is different from the Intel format.

I don't care much about it because I rarely deal with him at work (the software I use has been processed internally.

During programming today, we found that we need to convert four byte types of data into ieee754 standard data and compile a function for processing.

 

1 unit unit2;
2
3 Interface
4
5 uses
6 windows, messages, sysutils, variants, classes, graphics, controls, forms,
7 dialogs, stdctrls;
8
9 type
10 tform2 = Class (tform)
11 edt1: tedit;
12 edt2: tedit;
13 edt3: tedit;
14 edt4: tedit;
15 edt5: tedit;
16 btn1: tbutton;
17 procedure btn1Click (Sender: TObject );
18 private
19 {Private declarations}
20 public
21 {Public declarations}
22 end;
23
24 var
25 Form2: TForm2;
26
27 implementation
28
29 {$ R *. dfm}
30 {convert four bytes into IEEE754 data}
31 function PackByteToFloat (byte1, byte2, byte3, byte4: byte): Single;
32 var
33 input: array [1 .. 4] of byte; {define an array to store the input four bytes}
34 output: PSingle;
35 begin
36 input [1]: = byte1;
37 input [2]: = byte2;
38 input [3]: = byte3;
39 input [4]: = byte4;
40 output: = Addr (input); {use the address retrieval method for processing}
41 Result: = output ^; {obtained data in intel format}
42 end;
43
44 procedure TForm2.btn1Click (Sender: TObject );
45 var
46 byte1, byte2, byte3, byte4: byte;
47
48 begin
49 byte1: = StrToInt (edt1.Text );
50 byte2: = StrToInt (edt2.Text );
51 byte3: = StrToInt (edt3.Text );
52 byte4: = strtoint (edt4.text );
53
54 edt5.text: = floattostr (packbytetofloat (byte1, byte2, byte3, byte4 ));
55
56 end;
57
58 end.
59

 

 

 

{☆Recommended ☆: rebate network. I will return you cash for online shopping, which is affordable! Save money new portal}

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.