#1,088 – How 32-Bit Floating Point Numbers Are Stored in .NET, part I

Floating point numbers in .NET (on Intel-based PCs) are stored using the IEEE 754 standard, which defines how to store both 32-bit (float) and 64-bit (double) floating points.

Floating point numbers are stored in memory by storing the value as a binary floating point value represented using scientific notation (binary).

For example, to store a decimal value of 7.25:

1088-001

The exponent is expressed as binary, so it has a value of 2.

We can now store this floating point number in memory by storing three things:

  • The sign of the number (positive)
  • The mantissa (1.1101)
  • The exponent (10)

On Intel-based PCs, 32-bit floating point numbers are stored as follows:

  • 1 bit to store the sign (0 for positive numbers, 1 for negative numbers)
  • 8 bits to store the exponent
  • 23 bits to store the mantissa

More coming in part II

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about .NET technologies. Equally passionate about my own personal projects related to family history and preservation of family stories and photos.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: