473,837 Members | 1,627 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 CAtgGalvanoMach ine::Convert4By tesToFloat(BYTE byte1, BYTE byte2, BYTE
byte3, BYTE byte4)
DWORD l,ll,m,e;
float returnvalue=0,m antisse=0;

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


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

returnvalue=flo at(ldexp(1+mant isse, e-127));

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


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

Use the System.BitConve rter class.


Mattias Sjögren [MVP] mattias @ mvps.org
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.ToDo uble(bytearray)

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

Try BitConverter.To Single()

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


Nov 15 '05 #3

thats it


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

Their is a method for double :

BitConvert.ToDo uble(bytearray)

but this requiers a 8 Byte array. Theirs no BitConvert.ToFl oat()
Try BitConverter.To Single()

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

other words)


Nov 15 '05 #4

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

Similar topics

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 page: http://members.aol.com/hikksnotathome/hideAndShowDivs/testPage.html IE6 and Opera7 display it as I want it.
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 I have tested (IE5, IE5.5, IE6, NN6, NN7, Mozilla 1.7, FireFox0.8) except Opera, which refuses to respect my "float:right" rule (I think). Any solutions? Alternatively, is there a better way to achieve this same effect? I tried to do it...
by: remi | last post by:
Can someone give me the smallest float(4 bytes) > 1.0f in oct and hex forms?
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 integers, it is easy, I can get the 4 bytes by anding like: byte1 = int_val & 0x000000FF byte2 = int_val & 0x0000FF00 byte3 = int_val & 0x00FF0000
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 it? the following code doesn't show up any error during compile time but crashes at runtime telling "unrecognized or unsupported array type": array<float>^ vals = gcnew array<float>(dimension); pin_ptr<float>ss=&vals; unmanaged_function(ss);
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
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 ( http://scripts.ringsworld.com/database-tools/xls2mysql/inc/Excel/reader.php.html ) Somewhere there happens a exponent to float conversion so that strings as 1E3 2E9 are converted to their floating point values. I'm trying to put this functionality off...
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
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 of the blue of box, only the orange 'AAA' box floated to the right, exactly as I expect. In IE, however, the blue box fills the page width 100%. It's as if it has lost its float. I've been searching for a few hours, and although there are a lot...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.