473,378 Members | 1,580 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,378 software developers and data experts.

HOWTO? float to 4 Bytes, 4 Bytes to float

Hallo NG,

a few jears ago i made myself in c++ a funktion to convert 4 Byte to one
float variable:

//################################################## #########
// Make from 4 Bytes one float variable wich is 4 bytes long
//################################################## #########
float CAtgGalvanoMachine::Convert4BytesToFloat(BYTE byte1, BYTE byte2, BYTE
byte3, BYTE byte4)
{
DWORD l,ll,m,e;
float returnvalue=0,mantisse=0;

l = byte1;
l = l << 24;
ll = byte2;
l = l | (ll << 16);
ll = byte3;
l = l | (ll << 8);
ll = byte4;
l = l | ll;

e=l&0x7f800000;
e>>=23;
m=l&0x7fffff;

for(int i=0; i<=23;i++)
{
if(TestBit(m,unsigned int(ldexp(1,i))))
{
mantisse+=float((ldexp(1, i-23)));
}
}

returnvalue=float(ldexp(1+mantisse, e-127));

return returnvalue;
}
Is their now a ready function in the framework?
and for the other way float to 4 bytes?

Regards

Michael
Nov 15 '05 #1
3 54717
>Is their now a ready function in the framework?
and for the other way float to 4 bytes?


Use the System.BitConverter class.

Mattias

--
Mattias Sjögren [MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/
Please reply only to the newsgroup.
Nov 15 '05 #2
> but how do I Convert this Byte array back into float?

Their is a method for double :

BitConvert.ToDouble(bytearray)

but this requiers a 8 Byte array. Theirs no BitConvert.ToFloat()


Try BitConverter.ToSingle()

This is a single precision IEEE-754 floating point number (a float in other
words)

Oscar.

Nov 15 '05 #3
Thanks,

thats it

Regards

Michael
"Oscar Papel" <oe*****@rogers.com> schrieb im Newsbeitrag
news:O6**************@TK2MSFTNGP12.phx.gbl...
but how do I Convert this Byte array back into float?

Their is a method for double :

BitConvert.ToDouble(bytearray)

but this requiers a 8 Byte array. Theirs no BitConvert.ToFloat()
Try BitConverter.ToSingle()

This is a single precision IEEE-754 floating point number (a float in

other words)

Oscar.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: HikksNotAtHome | last post by:
This page displays as I want it to (for the way its coded). http://members.aol.com/hikksnotathome/hideAndShowDivs/index.html When I try to move the Up/Down Arrow over to the right, as in this...
1
by: Kyle James Matthews | last post by:
Hello, I am curious if any of you have a solution to a problem I am having on this page: <http://www.digitalovertone.com/new/index2.php>. The navigation bar displays correctly on every browser...
3
by: remi | last post by:
Can someone give me the smallest float(4 bytes) > 1.0f in oct and hex forms?
4
by: Michael Yanowitz | last post by:
Hello: For some reason I can't figure out how to split a 4-byte (for instance) float number (such as 3.14159265359) into its 4-bytes so I can send it via a socket to another computer. For...
5
by: xxx | last post by:
Hi all, i'm new in visual c++ and i'm having troubles converting types. Let me explain: i have an unmanaged c++ function that wants an float* parameter but i have an array<float>^, how i can covert...
6
by: cok119 | last post by:
Hi, all How can I add '+' or '-' before float value using float.ToString(fotmat-string) ? What's the format string should used ? thanks
1
by: malick | last post by:
Hello it developers, I'm using PHPExcelReader which I downloaded from sourceforge (http://sourceforge.net/projects/phpexcelreader) To read excel xls files in php. In the file reader.php (...
8
by: Tom Impelluso | last post by:
Hi! I have used both of these "float *f" and "float* f" Could someone tell me if one is preferred and why? Yes, i know both
1
by: desheffer | last post by:
Hello all, I'm having an issue with (something like) the following: <div style="background:blue; float:right;"> <div style="background:orange; float:right;">AAA</div> </div> In FF, I see none...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.