converting byte to float

A

Aykut

Hi
I have to convert byte value to float in C#.Float is in IEEE 754 format.
byte value is= 70 23 22 195 in a byte array.
and its float value is = -150.0909
what is the algoritm for this conversion?
thanks for help
 
M

Morten Wennevik

Hi Aykut,

You can use a MemoryStream to create a Stream of your byte data, then read a float (Single) from the stream using a BinaryReader.

byte[] b = new byte[]{70, 23, 22, 195};
float f = 0;
using(MemoryStream ms = new MemoryStream(b))
{
using(BinaryReader br = new BinaryReader(ms))
{
f = br.ReadSingle();
}
}
 
G

Guest

byte value is= 70 23 22 195 in a byte array.
and its float value is = -150.0909
what is the algoritm for this conversion?

I think System.BitConverter might do what you want.

public static float ToSingle(
byte[] value,
int startIndex
);
 
A

Aykut

Thanks for the replies .
But I d rather like to know the algorithm behind it.
if it isnt too complicated :)
regards
 

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

Top