How to Convert a Number from Decimal to IEEE 754 Floating Point Representation

Download ArticleDownload Article

Unlike humans, computers do not utilize the base 10 number system. They use a base 2 number system that allows for two possible representations, 0 and 1. Thus, numbers are written very differently in IEEE 754 than in the traditional decimal system that we are used to. In this guide, you will learn how to write a number in both IEEE 754 single or double precision representation.

For this method, you will need to know how to convert numbers into binary form. If you don't know how to do this, you can learn how in How to Convert from Decimal to Binary.

  1. How.com.vn English: Step 1 WH.performance.clearMarks('image1_rendered'); WH.performance.mark('image1_rendered');...
    Choose single or double precision. When writing a number in single or double precision, the steps to a successful conversion will be the same for both, the only change occurs when converting the exponent and mantissa.
    • First we must understand what single precision means. In floating point representation, each number (0 or 1) is considered a “bit”. Therefore single precision has 32 bits total that are divided into 3 different subjects. These subjects consist of a sign (1 bit), an exponent (8 bits), and a mantissa or fraction (23 bits).
    • Double precision, on the other hand, has the same setup and same 3 parts as single precision; the only difference is that it will be larger and more precise number. In this case, the sign will have 1 bit, the exponent will have 11 bits and the mantissa will have 52 bits.
    • In this example will convert the number 85.125 into IEEE 754 single precision.
  2. How.com.vn English: Step 2   Separate the whole and the decimal part of the number.
    Take the number that you would like to convert, and take apart the number so you have a whole number portion and a decimal number portion. This example will use the number 85.125. You can separate that into whole number 85, and the decimal 0.125.
    Advertisement
  3. How.com.vn English: Step 3   Convert the whole number into binary.
    [1] This would be the 85 from 85.125, which will be 1010101 when converted into binary.
  4. How.com.vn English: Step 4   Convert the decimal portion into binary.
    [2] This would be the 0.125 from 85.125, which will be 0.001 when converted into binary.
  5. How.com.vn English: Step 5   Combine the two parts of the number that have been converted into binary.
    [3] For instance, the number 85 in binary is 1010101 and the decimal portion 0.125 in binary is .001. When you combine them using a decimal point, you end up with 1010101.001 as your final answer.
  6. How.com.vn English: Step 6  Convert the binary number into base 2 scientific notation.
    You can convert the number into base 2 scientific notation by moving the decimal point over to the left until it is to the right of the first bit. These numbers are normalized which means the leading bit will always be 1. As for the exponent, the number of times that you moved the decimal will be your exponent in base 2 scientific notation.[4]
    • Remember that moving the decimal to the left will result in a positive exponent while moving the decimal to the right will result in a negative exponent.
    • For our example, you will need to move the decimal 6 times in order to get it to the right of the first bit. The resulting notation will be , this number will be used in future steps.
  7. How.com.vn English: Step 7   Determine the sign of the number and display in binary format.
    You will now determine if your original number is positive or negative. If the number is positive, you will record that bit as 0, and if it is negative, you will record that bit as 1.[5] Since your original number, 85.125, is positive, you will record that bit as 0. This will be the first bit out of the 32 total bits in your IEEE 754 single precision representation.
  8. How.com.vn English: Step 8   Get the exponent based on precision.
    There are set biases for both single and double precision. The exponent bias for single precision is 127, which means we must add the base 2 exponent found previously to it. Thus, the exponent you will use is 127+6 which is 133.
    • Double precision as perceived from the name is more precise and can hold larger numbers. Therefore its exponent bias is 1023. The same steps used for single precision apply here, so the exponent you can use to find double precision is 1029.
  9. How.com.vn English: Step 9  Turn the exponent into binary.
    After you determine your final exponent, you will need to convert it into binary so that it could be used in the IEEE 754 conversion. For the example, you can convert the 133 that you found in the last step into 10000101.
  10. How.com.vn English: Step 10  Determine the mantissa.
    The mantissa aspect, or the third part of the IEEE 754 conversion, is the rest of the number after the decimal of the base 2 scientific notation. You will just drop the 1 in the front and copy the decimal portion of the number that is being multiplied by 2. No binary conversion needed! For the example, the mantissa would be 010101001 from .
  11. How.com.vn English: Step 11   Compile 3 parts into one final number.
    • Finally, you will compile all that we have calculated thus far into your conversion. It will first begin with a 0 or 1 bit that you determined in step 7 based on sign. For the example, you will have a 0 to start it.
    • Next up, you will have the exponent section that you determined in step 9. For the example, your exponent will be 10000101.
    • Now, you have the mantissa, which is the third and last part of the conversion. You derived this earlier when you took the decimal portion of the base 2 conversion. For the example, the mantissa would be 010101001.
    • Finally, you combine these all together. The order should go sign-exponent-mantissa. After you connect those three binary numbers, you then fill out the rest of the mantissa with 0s.
    • For the example the solution is 0 10000101 01010100100000000000000 as 85.125 converted into IEEE 754 format.
  12. Advertisement

Expert Q&A

Ask a Question
200 characters left
Include your email address to get a message when this question is answered.
Submit
      Advertisement

      Video

      Tips

      Submit a Tip
      All tip submissions are carefully reviewed before being published
      Thanks for submitting a tip for review!

      About This Article

      How.com.vn English: Grace Imson, MA
      Reviewed by:
      Math Teacher
      This article was reviewed by Grace Imson, MA. Grace Imson is a math teacher with over 40 years of teaching experience. Grace is currently a math instructor at the City College of San Francisco and was previously in the Math Department at Saint Louis University. She has taught math at the elementary, middle, high school, and college levels. She has an MA in Education, specializing in Administration and Supervision from Saint Louis University. This article has been viewed 343,608 times.
      495 votes - 89%
      Co-authors: 10
      Updated: January 17, 2024
      Views: 343,608
      Categories: Conversion Aids
      Thanks to all authors for creating a page that has been read 343,608 times.

      Reader Success Stories

      • How.com.vn English: Madhu R.

        Madhu R.

        Nov 21, 2023

        "I never got this much clear explanation anywhere. Awesome article!"
      Share your story

      Did this article help you?

      ⚠️ Disclaimer:

      Content from Wiki How English language website. Text is available under the Creative Commons Attribution-Share Alike License; additional terms may apply.
      Wiki How does not encourage the violation of any laws, and cannot be responsible for any violations of such laws, should you link to this domain, or use, reproduce, or republish the information contained herein.

      Notices:
      • - A few of these subjects are frequently censored by educational, governmental, corporate, parental and other filtering schemes.
      • - Some articles may contain names, images, artworks or descriptions of events that some cultures restrict access to
      • - Please note: Wiki How does not give you opinion about the law, or advice about medical. If you need specific advice (for example, medical, legal, financial or risk management), please seek a professional who is licensed or knowledgeable in that area.
      • - Readers should not judge the importance of topics based on their coverage on Wiki How, nor think a topic is important just because it is the subject of a Wiki article.

      Advertisement