Re: Binary representation of a double?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Thanks José!

That is what my book on numerical mathematics told me as well. Unfortunatly
the real binary representation (on "little endian") systems differs from this
specification.

Hopefully I post the answer here in a few days.

Regards,
Martijn Kaag

"José Manuel Agüero" wrote:

Hello vecozo,

The binary representation of a double is, in fact (with the bytes ordered):

SEEEEEEE EEEEMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM

The first bit of the mantissa is omitted and is always 1 for normalized numbers.

The precision P of the representation of a double D is: D * 2 ^ -53 <= P < D * 2 ^ -52.
If you take the exponent E, the precision is exactly 2 ^ (E - 53)

For more information, visit, for example:
IEEE Standard 754 Floating Point Numbers
http://steve.hollasch.net/cgindex/coding/ieeefloat.html
What Every Computer Scientist Should Know About Floating-Point Arithmetic
http://docs.sun.com/source/806-3568/ncg_goldberg.html

Regards.


<vecozo@xxxxxxxxxxxxx> escribió en el mensaje news:89E20A1D-1E20-402E-AAFC-539BC90C53AE@xxxxxxxxxxxxxxxx
| Hello,
|
| We are writing an application in C# that finds roots of a function up to
| machine precision. Therefore I have to compare the number of significant bits
| in two double variables (the upper- and lowerbound of the interval containing
| the root). Currently I am struggling with the binary representation of a
| double variable.
|
| I have written some test code and it seems that the binary representation of
| a double is given by:
|
| MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM EEESMMMM EEEEEEEE
|
| Where M denotes the mantissa, E the exponent and S the sign.
|
| The location of the least significant bit (*) is seems to be given by:
|
| MMMMMMM* MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM EEESMMMM EEEEEEEE
|
| And the most significant bit:
|
| MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM MMMMMMMM EEES*MMM EEEEEEEE
|
| This would mean that the mantissa part is written as:
|
| qrstuvwxy ijklmnop abcdefgh
|
| Where y is the least significant bit and a the most significant bit. This is
| kind of unfortunate, because we cannot simply use a bitwise shift operator to
| determine if all but the least significant bit are equal. Could you confirm
| if we have this bitwise structure correct?
|
| Regards,
| Martijn Kaag
|
| We use test code similar to the following to obtain the bitwise
| representation:
| > public string GetBitString (double d) {
| >
| > byte[] bytes = ToByte(d);
| > string rval = “”;
| > for (int b=0; b<8;b++) {
| > rval += GetBitString (bytes[b]) + “ ”;
| > }
| > return rval;
| > }
| > public unsafe Byte[] ToByte ( double d)
| > {
| >
| > *Byte[] byte;
| > &byte = (*Byte[])&d;
| > return byt;
| >
| > }
| >
| > public string GetBitString (byte b)
| > {
| > string rval = "";
| >
| >
| > for (int i=0; i <8;i++)
| > {
| > if (b>=126){
| > // alleen >=126 als meest significante bit in b = 1
| > rval += "1";
| > }
| > else {
| > rval += "0";
| > }
|
|
| ______________________________
| www.VECOZO.nl


.



Relevant Pages

  • Re: Binary representation of a double?
    ... The binary representation of a double is, in fact: ... The first bit of the mantissa is omitted and is always 1 for normalized numbers. ... because we cannot simply use a bitwise shift operator to ...
    (microsoft.public.dotnet.framework)
  • Re: Different binary results with different PHP versions
    ... I am doing some bitwise ... I have come accross to different results ... Returns a string containing a binary representation of the given number ...
    (comp.lang.php)
  • Writing a float or doubles byte values
    ... I would like to print (cout) the binary representation of a double. ... A typical output would be something like ... M = mantissa bits ...
    (comp.lang.cpp)