0

Hello there I need to store 0.2730 using IEEE format. Now what I did was to set the sing at 0 because the number is positive. Now I thought that that since what’s before the point is 0 then I don’t have to do any conversion to it because 0 in binary it’s just 0 so the exponent would end up being 0 and I just needed to convert 127 to binary. When I looked for the Mantissa I tried to do the pattern when I multiply the decimal part by 2 and take out the number before the I can’t find a pattern nor it reaches 0 so what I did was just multiply until I found 23 bits. Now when I looked up the real value it says that the exponent should be 125 and that the number is actually 0 0111 0001 0111 1000 1101 0101 000. Now I don’t know why I have to subtract 2 from the exponent since I think I don’t have to move the point nor when to stop when doing the multiplication by 2 pattern. I left a picture of my work in case it helps. Thanks in advance and hope you are doing well

enter image description here

ycaquino80
  • 23
  • 4
  • Language: "Storing 0.2730 as IEEE" makes sense, because 0.2730 is a value, and IEEE is a format. "Converting" doesn't make sense unless you mean "0.2730" is a value stored in a different format, such as a base10 string, and you're converting from one format the other. "Floating point to binary" doesn't make sense because floating point is a binary format. – Mooing Duck Jun 15 '20 at 17:37
  • Just because the first digit is a zero does NOT mean that the exponent is zero. You need to reread how to determine the exponent. You've also forgotten about the "implied 1". – Mooing Duck Jun 15 '20 at 17:41
  • From what I understood when you store it in IEEE 754 format you break the number into it's whole part and the decimal part. You convert each one to binary then join the whole part and the decimal part separated by the decimal point. then you move the the decimal point until you reach a scientific notation structure 1.XXXX (x are just placeholders for numbers) So I thought since my whole part was already in binary and i was just 1 number then I didn't need to move the point. What is that implicit 1 ? Also what do you mean by a floating point is a binary number ? – ycaquino80 Jun 15 '20 at 17:58
  • "since my whole part was already in binary and i was just 1 number then I didn't need to move the point." You converted the whole part to "01000...", which is clearly not scientific notation structure 1.XXXX, since it starts with a zero. So you _do_ need to move the point. Also, floating point format has an implicit 1, to save storage space. You should reread that section. Finally, since you've noted the IEEEE format is made of 0s and 1s.... that makes it a binary format. It's a different binary format than the twos-compliment format that we use for integers, but they're both binary formats. – Mooing Duck Jun 15 '20 at 19:24
  • @MooingDuck: “Convert” 0.2730 to IEEE-754 binary32 does make sense. A conversion is a change from one way of representing a thing to another way of representing it. “0.2730” is a decimal way of representing the number. IEEE-754 binary32 is another way. – Eric Postpischil Jun 15 '20 at 20:47

2 Answers2

1

IEEE-754 binary32 encoding

The sign of 0.2730 is positive, so the sign bit in IEEE-754 binary32 format will be zero.

Next, represent the number with an explicit scaling by a power of 2: 0.2730 = 0.2730 • 20. In this, we call the part before the “•” (0.2730) the significand, and the power that 2 is raised to is the exponent.

Then, adjust this representation to make the significand be at least 1 and less than 2. The allowed adjustments are to adjust the exponent by increments of one and multiply or divide the significand by 2 accordingly: 0.2730 • 20 = 0.5460 • 2−1 = = 1.0920 • 2−2.

This is called the normalized form. The exponent in this form, −2 is used for the encoding. To encode it in the exponent bits, we add the fixed bias of the format, 127, and write the result in 8-bit binary. −2 + 127 = 125, and 125 in binary is 01111101.

Next, write the significand in binary to at least 24 digits: 1.0920 = 1.0001011110001101010011111101111100111011…2. The bold shows the first 24 digits. We can only use 24 digits in the IEEE-754 binary32 format, and we see the remaining part is above half of the 24th digit, so we will round up, producing 1.000101111000110101010002. That is our significand in binary. (For information on doing this, see “Decimal to binary” below.)

To encode the significand, we use the 23 digits after the “.” (The leading digit is known to be 1, because we normalized the number to make it so, so it does not need to be included in the bits that primarily encode the significand.) Those bits are 00010111100011010101000.

Then we put the sign, exponent, and significand bits together: 0 01111101 00010111100011010101000.

Decimal to binary

To convert the decimal numeral 1.0920 to binary:

  • Write the leading “1” and remove it, giving .0920. Multiply by two, giving 0.1840. Also write “.” since we start at this point.
  • Write the leading “0” and remove it, giving .1840. Multiply by two, giving 0.3680.
  • Write the leading “0” and remove it, giving .3680. Multiply by two, giving 0.7360.
  • Write the leading “0” and remove it, giving .7360. Multiply by two, giving 1.4720.
  • Write the leading “1” and remove it, giving .4720. Multiply by two, giving 0.9440.

Continue as long as desired.

Community
  • 1
  • 1
Eric Postpischil
  • 195,579
  • 13
  • 168
  • 312
  • "The exponent in this form, −2 is used for the encoding." It's worth calling out that this is why his exponent was off by 2 on the whiteboard. – Mooing Duck Jun 15 '20 at 21:05
  • "write the significand in binary to at least 24 digits" You need the 25th digit (but no further) to determine the rounding. – Mooing Duck Jun 15 '20 at 21:07
  • @MooingDuck: If the 25th digit is 1, you do not know whether the residue is exactly ½ or more than ½ of the 24th digit without further information. – Eric Postpischil Jun 15 '20 at 21:11
  • You're right, I forgot that it's not always half-round-up. IEEE is.... round even? That would require more digits. – Mooing Duck Jun 15 '20 at 21:11
  • 2
    @MooingDuck: The common rounding is round-to-nearest-ties-to-even. So you need the 24th digit (to know whether it is even or not), the 25th digit (to know whether it is below ½ or not), and whether the residue after the 25th digit is zero or not (to distinguish exactly ½ from more than ½). So you do not need the 26th digit and beyond, just to know whether there was a residue after producing the 25th digit. – Eric Postpischil Jun 15 '20 at 21:14
0

It's hard to see what's in your picture, but here's the binary lay-out for your number 0.2730 both as a single-precision and double-precision IEEE-754 representation. Hopefully you can use it to double-check your answer. If you've a mismatch, feel free to ask a more specific question.

Here's 0.2730 in single-precision (32 bit) IEEE-754 representation:

                  3  2          1         0
                  1 09876543 21098765432109876543210
                  S ---E8--- ----------F23----------
          Binary: 0 01111101 00010111100011010101000
             Hex: 3E8B C6A8
       Precision: SP
            Sign: Positive
        Exponent: -2 (Stored: 125, Bias: 127)
       Hex-float: +0x1.178d5p-2
           Value: +0.273 (NORMAL)

And here's the same, this time in double-precision (64 bit) IEEE754 representation:

                  6    5          4         3         2         1         0
                  3 21098765432 1098765432109876543210987654321098765432109876543210
                  S ----E11---- ------------------------F52-------------------------
          Binary: 0 01111111101 0001011110001101010011111101111100111011011001000110
             Hex: 3FD1 78D4 FDF3 B646
       Precision: DP
            Sign: Positive
        Exponent: -2 (Stored: 1021, Bias: 1023)
       Hex-float: +0x1.178d4fdf3b646p-2
           Value: +0.273 (NORMAL)
alias
  • 28,120
  • 2
  • 23
  • 40