Home > Net >  How to convert hexadecimal to 4 bytes floating-point number
How to convert hexadecimal to 4 bytes floating-point number

Time:10-11

How to convert hexadecimal to 4 bytes, floating point on VS platform written in c #, with controls make a hexadecimal conversion with floating-point small software, hope to have a master can stick the code out to look at, thank you very much! Be urgent! Be urgent! Be urgent!

CodePudding user response:

You can use BitConverter ToDouble

CodePudding user response:

 static void Main (string [] args) 
{
Var a=1234.5 f;
Var b=BitConverter. GetBytes (a);
Var c=BitConverter. ToString (b) Replace (" - ", "");
Console. WriteLine (c);
B=BitConverter. GetBytes (Convert. ToInt32 (c, 16));
Console. WriteLine (BitConverter. ToSingle (b.R everse (). The ToArray (), 0));
}

CodePudding user response:

B.R everse is () in the second floor?

CodePudding user response:

Pay attention to the byte order, Reverse () bytes is upside down, on the Intel processor, the low byte in the front, some platform is on the contrary,

CodePudding user response:

From 16 mechanism of four bytes array to floating-point number:
Byte [] bytes=new byte [4].
BitConverter. ToSingle (bytes, 0);
  •  Tags:  
  • C#
  • Related