Converting bit patterns to IEEE 754 Single Precision equivalents

Converting bit patterns to IEEE 754 Single Precision equivalents

The IEEE 754 standard defines how floating point numbers are stored in binary form. In this tutorial we convert a bit pattern into its' base 10 equivalent.

Test Case

Given a 32-bit base 2 number:

0100 0010 0010 1001 1110 0100 0000 00002


This bit pattern has no inherent encoding, but if we assume that it represents an IEEE 754 single precision number, we can convert it to base 10.

Sign
Exponent (biased 127)
Fraction (without the leading '1')
0
100 0010 0
010 1001 1110 0100 0000 0000
 
 
 
 
 
 
The IEEE 754 Single Precision Standard mapping of the bits

Calculate the exponent

Exponent = 128 + 4 = 132

Subtracting the bias of 127, we get 5. Therefore we will need to shift the fraction 5 places to the right.

Calculate the Fraction

Fraction = 1.010 1001 1110 0100 0000 0000 (base 2)

The leading '1' is not stored in the original bit pattern. According to the IEEE 754 standard, a leading '1' is always assumed.

Apply the 'hidden' digit to the right of the radix point

One solution is 1.010 1001 1110 0100 0000 00002 X 25

This solution is unwieldy since it is in base 2.

Apply the exponent to the fraction by sliding the radix point

Another solution is 1010 10.01 1110 0100 0000 0000

This solution is unwieldy since it is in base 2.

Convert the resulting bit pattern to powers of 2

Another solution is (20+2-2+2-4+2-7+2-8+2-9+2-10+2-13) * 25


Apply the exponent to the powers of 2

Another solution is (25+23+21+2-2+2-3+2-4+2-5+2-8)

Converting each position to base 10 and adding gives us:

 
32.
 8.
 2.
  .25
  .125
  .0625
  .03125
  .00390625
============
42.47265625  

Therefore,

0100 0010 0010 1001 1110 0100 0000 00002 converts to = 42.4726562510

More by this Author

  • The Importance of Doing Laundry
    19

    We could nag, but this is better. It is less work for us to use the words of others to emphasize the importance of doing laundry. Besides, if you saw the way we dressed, you'd laugh your mouse off.

  • EDITOR'S CHOICE
    Data Hiding in Java
    12

    Data Hiding is an aspect of Object Oriented Programming (OOP) that allows developers to protect private data and hide implementation details. In this tutorial we examine basic data hiding techniques in Java.

  • EDITOR'S CHOICE
    Introduction to Windows Notepad
    5

    A useful text editor is an essential component of any personal computer. Every day we need to make notes, compose documents, and record vital pieces of information. We depend on our text editor. Microsoft provided...


Comments 2 comments

ICnow 6 years ago

Awesome! Best explanation on the web! Perfect!


nicomp profile image

nicomp 6 years ago from Ohio, USA Author

@ICnow: Thanks.

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working