By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,526 Members | 2,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,526 IT Pros & Developers. It's quick & easy.

converting byte to float

P: n/a
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
Nov 17 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
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();
}
}

--
Happy coding!
Morten Wennevik [C# MVP]
Nov 17 '05 #2

P: n/a
> 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
);
Nov 17 '05 #3

P: n/a
Thanks for the replies .
But I d rather like to know the algorithm behind it.
if it isnt too complicated :)
regards
Nov 17 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.