473,396 Members | 1,726 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

converting byte to float

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
3 5661
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
> 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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Giovanni Azua | last post by:
Hello all, I need to return back to TSQL two numeric values from an Extended Stored Procedure developed in C. As result my C dll program produces two float values, the TSQL side expects to have...
8
by: Rick | last post by:
Hi, Does C have some handy functions to convert chars, ints and floats to bit arrays? I need to store that stuff binary so a few functions would be great. Converting chars and ints isn't...
2
by: Benjamin Rutt | last post by:
Does anyone have C code laying around to do this? I have to read in some binary data files that contains some 4-byte IBM/370 floating point values. I would like a function to convert 4-byte...
2
by: Sisnaz | last post by:
I'm reading byte information from a C++ program via TCP sockets. At one time I thought I came across away to convert C Float data type into a VB single data type. I'm reading the C data type in...
9
by: Gregory.A.Book | last post by:
I am interested in converting sets of 4 bytes to floats in C++. I have a library that reads image data and returns the data as an array of unsigned chars. The image data is stored as 4-byte floats....
116
by: Dilip | last post by:
Recently in our code, I ran into a situation where were stuffing a float inside a double. The precision was extended automatically because of that. To make a long story short, this caused...
4
by: Yasin Cepeci | last post by:
I ve get float data from serial port. I ve taken it in the form of hex by modbus protocol. I know it is float but I couldnt convert it there is a few sample data below; B3 33 43 34 = 180.699997...
2
by: John Fisher | last post by:
Hi Group, troubles with converting signed 32.32, little-endian, 2's complement back to floating point. I have been trying to brew it myself. I am running Python 2.5 on a Mac. Here is the C-code...
9
by: ssubbarayan | last post by:
Hi all, I am trying a program to convert floating point values to a byte array and printing the same to the screen.The idea behind this is we already have an existing function which can do byte...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.