Grayish
Grayish

Reputation: 187

c - understanding floating point binary model

So I'm having trouble understanding floating point binary representation. I have an image below from my teacher's notes but I don't understand how they got the string of digits for the 8-bit exponent and 23-bit mantissa for each of the rows.

So the teacher represents 284 as 100011100 = 1.000111 x 2^8. I get that the bit sign is 0 because it's a positive number. I have no idea where the 8-bit exponent of 00001000 came from, and the 23-bit mantissa seems to be a larger representation of 1.000111 that fills in 23 bits.

I was wondering if someone could explain how the teacher was able to fill in the chart/get the values from converting 100011100 into 1.000111 x 2^8? I tried watching tutorials and looking on other sites but I'm still very confused.

I would also appreciate if someone could explain how the teacher went from having the values in the first row to changing them to an 8-bit exponent of 10000111 and a 23-bit mantissa of 000 1110 0000 0000 0000 0000 as shown in the 3rd row. Any help would be appreciated, I've been staring at this part of my notes for hours but I just can't seem to comprehend the logic behind all this. It all seems so complex and overwhelming.

enter image description here

Upvotes: 3

Views: 677

Answers (3)

//unsigned int s... x... n...

s xxxxxxxx nnnnnnnnnnnnnnnnnnnnnnn

float==(-1) ^ s * (1 + n * 2 ^ -23) * (2 ^ (x - 127))

Upvotes: 0

Eric Postpischil
Eric Postpischil

Reputation: 223161

So the teacher represents 284 as 100011100 = 1.000111 x 2^8. I get that the bit sign is 0 because it's a positive number. I have no idea where the 8-bit exponent of 00001000 came from,…

The exponent in of 2 in 1.000111 × 28 is 8. 8 in binary is 1000, or 00001000.

Later, 127 is added to the exponent. This is just a matter of how the exponent is stored. Instead of any other method of representing positive a negative exponents, it is just a rule that 127 is added to the exponent before storing it. So if the exponent is 8 (00001000), we add 127 to get 135 (10000111) and store that in the exponent field. This gives us a way of storing negative exponents. If the exponent is −1, we store −1 + 127 = 126. If the exponent is −126, we store −126 + 127 = 1.

I would also appreciate if someone could explain how the teacher went from having the values in the first row to changing them to an 8-bit exponent of 10000111 and a 23-bit mantissa of 000 1110 0000 0000 0000 0000 as shown in the 3rd row.

For normal numbers, we remove the first bit from the significand1 and store the next 23 bits in the significand field. So, with the significand 1.000111, we remove the leading 1 to get .000111, and then we store 000111 followed by zeros. (A normal number is any representable number at or above the minimum exponent scale for the format, which is 2−126 for the IEEE-754 32-bit binary format. For subnormal numbers, the leading bit is stored explicitly, with a modification to how the exponent is handled.)

Footnote

1 “Significand” is the preferred term for the fraction portion of a floating-point representation. “Mantissa” is an old term for the fraction portion of a logarithm. Significands are linear. Mantissas are logarithmic.

Upvotes: 1

S.S. Anne
S.S. Anne

Reputation: 15586

OK, so the first bit is the sign bit. If this bit is set, then the number is negative.

After that, the next 8 bits (in a float) are the exponent. 127 is subtracted from the exponent and from there the number is multiplied by 2^exponent.

Finally, the nest 23 bits are the mantissa. This is complicated, but essentially, this contains the decimal part of the number.

I found this YouTube video informational about how to convert a number to the IEEE-754 float format. You should take a look at it: Decimal to IEEE 754 Floating Point Representation.

Upvotes: 0

Related Questions