conversion

  • Thread starter Thread starter Frank
  • Start date Start date
F

Frank

Hello all,
I am reading a serial device and I get 4 separate bytes (byte[4]). Put
together they form a Float type. How can I put these bytes together and get
a float?
Any ideas?
Thanks
Frank
 
You could try BitConverter.ToSingle, but watch out for endianness, as
the endianness of BitConverter is fixed by your CPU architecture. You
could always check .IsLittleEndian and swap bytes as necessary, else
Jon Skeet has an EndianBitConverter class here:
http://www.yoda.arachsys.com/csharp/miscutil/

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top