浮点高低位赋值
C++
typedef union uib { float av; byte bi[4]; } tv; ListBox1->Clear(); tv avalue; for (int i = 0; i < 4; i++) { avalue.bi[3 - i] = Memo1->Lines->Strings[i].ToInt(); } this->Caption = avalue.av; ListBox1->Items->Add(this->Caption);
Delphi
// 单精度浮点数(4字节) TSingleRec = record case Integer of 0: (Value: Single); 1: (bLL, bLH, bHL, bHH: Byte); end; procedure TFrMainform.btnUnioClick(Sender: TObject); var asr: TSingleRec; begin asr.bHH := $46; asr.bHL := $A6; asr.bLH := $C3; asr.bLL := $C8; self.Caption := asr.Value.ToString(); end;
0x40
0x0F
0x85
0x1F
》2.24
0x43
0x0E
0x2B
0x0F
》142.17
0x46
0xA6
0xC3
0xC8
》21345.89