×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

float binary format
3

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;
}

John Fill


ivfmd@mail.md

RE: float binary format

Hello, John!

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

(OP)
1. You didn't answer to my question. I asked about format, but you answered me about size of.
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

Greetinx!

John, i send you info by email!

Happy programming!))

RE: float binary format

(OP)
thanks but was good if you posted the answer in the forum.

John Fill


ivfmd@mail.md

RE: float binary format

Greetinx!
 
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

2
Knowing the general format is of course not enough.  You may also be interested in the ACTUAL format for each field.

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."

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close