ieee 754 converter

Status
Not open for further replies.

suchismitadeb

Beta member
Messages
1
Location
India
can anybody pls send me the code for converting a decimal no. into its ieee 754 equivalent (32 bit) using c++, java or .net... pls help!!!!!!!!!!!!!!!
 
IEEE 754 Converter

Can you send me the source code? I need to convert format x to format y.

This source code for this converter doesn't contain any low level conversion routines. The conversion between a floating point number (i.e. a 32 bit area in memory) and the bit representation isn't actually a conversion, but just a reinterpretation of the same data in memory. This can be easily done with typecasts in C/C++ or with some bitfiddling via java.lang.Float.floatToIntBits in Java. The conversion between a string containing the textual form of a floating point number (e.g. "3.14159", a string of 7 characters) and a 32 bit floating point number is also performed by library routines. If you need to write such a routine yourself, you should have a look at the sourecode of a standard C library (e.g. GNU libc, uclibc or the FreeBSD C library - please have a look at the licenses before copying the code) - be aware, these conversions can be complicated.

I've converted a number to floating point by hand/some other method, and I get a different result. Your converter is wrong!

Possibly, but unlikely. The conversion routines are pretty accurate (see above). Until now, checking the results always proved the other conversion less accurate. In particular toggling the last bit can lead to the same result after rounding to a fixed number of decimal places. Please check the double precision result (bottom line in the converter) and compare the difference to the expected decimal result while toggling the last bit.
 
Status
Not open for further replies.
Back
Top Bottom