## float binary format

## float binary format

(OP)

Can someone tell me what is the binary format of float numbers? I think in asm is the same as in C++. You can try to run this code to understand me better:

#include<iostream>

using namespace std;

struct x

{

union

{

int i;

float f;

};

};

int main(int _args,char** _cmdline)

{

x a;

a.f=1.;

cout<<a.i<<endl;

a.i=1;

cout<<a.f<<endl;

return 0;

}

#include<iostream>

using namespace std;

struct x

{

union

{

int i;

float f;

};

};

int main(int _args,char** _cmdline)

{

x a;

a.f=1.;

cout<<a.i<<endl;

a.i=1;

cout<<a.f<<endl;

return 0;

}

John Fill

ivfmd@mail.md

## RE: float binary format

Number with floating point in asm has the same format as in cpp. Following note shows type of float and int numbers and its size.

Size of 'float' is 32 bites, of 'double' is 64 bites, of 'long double' aka 'Extended' is 80 bites.

The sizes of 'int' number are various in 16-th and 32-th bites versions of Windows. In Win-16 'int' has size equal 16 bites, 'long int' has 32 bites, but in Win-32 'int' has 32 bites, and 'long int' has 32 bites too.

So knowing sizes of each number type you can use them depend on your task.

Happy programming!))

## RE: float binary format

2. x16 operating systems are fossile already, and please forget about them. We are not in jurassic period.

3. You sayd me nothing new.

John Fill

ivfmd@mail.md

## RE: float binary format

## RE: float binary format

John, i send you info by email!

Happy programming!))

## RE: float binary format

John Fill

ivfmd@mail.md

## RE: float binary format

Following notes presents format of floating point numbers

4 bites float

Bit Description

31 - Sign

30-23 - Power

22-0 - Mantissa (real bites of the number)

8 bites float (double)

63 - Sign

62-52 - Power

51-0 - Mantissa

10 bites float (long double)

79 - Sign

78-64 - Power

63-0 - Mantissa

Field of 'power' contains power of number of '2' and defines scale multiplier for field of 'mantissa'.

Happy programming!))

Happy programming!))

## RE: float binary format

So here's a bit of an explanation of the individual fields. I don't really understand them that well either, but it just might be that you can understand them somehow.

Okay, first, let's consider the so-called SCIENTIFIC NOTATION. Here's an example:

1.2 x 10^1

Which is the number 12. Now, the floating point format used by IEEE is very similar to the scientific notation, only it is a base 2. Let's show the number 12:

1.1b x 2^3

Let's show the number 0.5:

1.0b x 2^-1

The interesting thing about using a base 2 scientific notation is that for almost all numbers, the significand (the number at the left) starts with a 1. So, in the IEEE float format, the initial 1 is "implied," it is no longer stored in the "mantissa" field. All that is stored are the digits after the decimal (binary?) point, which is why it is called the mantissa field and not the significand field. In Intel's 80-bit float format, the initial 1 is NOT implied, it is the first bit in the mantissa field, which means that bit 63 in the long double format is always set EXCEPT when the value is zero.

The used of an implied 1 solves another problem: multiple zeroes. A zero can be represented in this way:

0.0b x 2^0

and this way:

0.0b x 2^32

also this way:

0.0b x 2^-127

and also this way:

0.0b x 2^23

For the 32-bit format it would mean that there could be up to 256 representations of zero, all of which were, well, zero.

However, the use of an implied 1 presented a problem in representing zero. After all, a zero's significand starts with a 0, not a 1. So IEEE decided that when ALL bits in a floating point number were 0, the implied bit would be set to 0, so the number was a zero. (Note: I'm not sure if it's ALL bits or just the mantissa bits, but I'm .68 surer that it's ALL bits). The use of implied digits is termed "NORMALIZATION."

Now, to something a little more interesting. The power field. The power field is UNSIGNED, for a reason I can't quite comprehend. So what? So, well, how do we represent a number such as 0.25?

1.0b x 2^-2.

So as we see the 2's exponent for such a number would be negative. What, then did IEEE do? They decided that a BIAS would be subtracted from the power field. The bias for a 32-bit float number is 128, the bias for a 64-bit float is 1024. So as an example if a 0 is in the power field, and a 101 in the mantissa field, we have:

1.101b x 2^-128

Anyway I think the reason for this is that IEEE couldn't really decide as to what version of negative numbers to use. The Intel 80x86 and Pentium series use the two's complement representation of negative numbers; some other computers use a non-complemented negative numbers, whose main disadvantage was having a negative and positive zero. For the mantissa/significand, the non-complemented version is used, which is easier on the hardware, but having a two's complement exponent was easier to implement on the hardware. So they decided to skip using negative numbers altogether and use a BIAS instead.

"Information has a tendency to be free. Which means someone will always tell you something you don't want to know."