Converting Decimal Numbers to Floating Point Representation

  • Thread starter Thread starter XodoX
  • Start date Start date
  • Tags Tags
    Floating Point
Click For Summary

Discussion Overview

The discussion revolves around the conversion of decimal numbers, specifically -45 and 3.54625, into 32-bit floating point representation. Participants explore the methods and rules involved in this conversion process, including references to specifications and examples of binary representation.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • Some participants express uncertainty about how to convert negative decimal numbers and seek assistance.
  • Questions arise regarding the specific reference or rules being used for floating point representation.
  • There is a discussion about the IEEE 754 formats and the confusion surrounding the term "32-bit single precision."
  • One participant describes a method for converting decimal fractions to binary, detailing the process of multiplying by 2 and discarding the integer part to obtain successive bits.
  • Another participant questions the reasoning behind selecting specific values during the conversion process, indicating a need for clarification on the steps involved.
  • Participants discuss the significance of the sign bit and the structure of the IEEE 754 representation, including the exponent and mantissa.
  • There is mention of alternative methods for converting fractions to binary, such as multiplying by powers of two, but challenges with this approach are acknowledged.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the best approach to converting the specified decimal numbers to floating point representation. Multiple competing views and methods are presented, and the discussion remains unresolved.

Contextual Notes

Participants reference various sources and methods for conversion, indicating a reliance on external materials for understanding the rules of floating point representation. There is also mention of potential confusion regarding the specifications of the numbers being converted.

XodoX
Messages
195
Reaction score
0
1. Convert -45 and 3.54625 32-bit ( single precision) to floating point representation.



I know how to convert positive and even decimal numbers, but I don't know how to do these. Is there somebody who knows? Help would be appreciated.
 
Physics news on Phys.org
XodoX said:
1. Convert -45 and 3.54625 32-bit ( single precision) to floating point representation.



I know how to convert positive and even decimal numbers, but I don't know how to do these. Is there somebody who knows? Help would be appreciated.

What reference are you using for floating point representation?
 
berkeman said:
What reference are you using for floating point representation?

What do you mean?
 
XodoX said:
What do you mean?

I mean what spec, or what rules? I can go to wikipedia to look it up, but I was hoping you could point me to what you are using. What textbook, or what other learning materials? How are you supposed to know how to do any conversions involving floating point?

I've done a few conversions involving floating point, and I have to look up the conversion rules each time I do.
 
berkeman said:
I mean what spec, or what rules? I can go to wikipedia to look it up, but I was hoping you could point me to what you are using. What textbook, or what other learning materials? How are you supposed to know how to do any conversions involving floating point?

I've done a few conversions involving floating point, and I have to look up the conversion rules each time I do.

doesn't matter how. I tried to to convert it to binary first and then go from there, using the formula I found, but that didn't work.
 
So which one of the IEEE 754 formats are you supposed to use?

http://en.wikipedia.org/wiki/Floating_point

Or is it when they say
3.54625 32-bit ( single precision)
that it's confusing? I don't know myself what they mean by a decimal number represneted by 32-bit single precision...
 
berkeman said:
So which one of the IEEE 754 formats are you supposed to use?

http://en.wikipedia.org/wiki/Floating_point

Or is it when they say that it's confusing? I don't know myself what they mean by a decimal number represneted by 32-bit single precision...

The floating point is going to look like this: 0 1111 1111 0110 1010 0100 0000 0000 0000

32 digits. The single precision is easy. I know how to do that once I know how to convert it. I saw that on wikipedia too. It's just not clear to me.
 
Negative numbers are easy if you know how to do positive numbers. You just flip the sign bit.

Floating point representation is essentially just scientific notation using base 2. To convert to base 2, first convert the integer part. Then multiply the fraction by 2. The integer part of the result is the next bit. To get successive bits, repeat the process of discarding the integer part and multiplying the resulting fraction by 2.

For example, the binary representation of 3.671875 starts with 11. After the binary point, the bits are

2x0.671875 = 1.34375
2x0.34375 = 0.6875
2x0.6875 = 1.375
2x0.375 = 0.75
2x0.75 = 1.5
2x0.5 = 1.0

So 3.671875 in decimal has the binary representation 11.1010112. Now you want to move the binary point all the way to the left, yielding 0.11101011_2\times2^2.

In IEEE 754 single-precision format, you first have the sign bit, 0 for positive and 1 for negative. Add an offset of 127 to the exponent and store the result in the next 8 bits. You then drop the first bit of the mantissa, because you know it's always 1, and store the rest in the remaining 23 bits. For our example, you'd have

0 10000001 11010110000000000000000

The first bit is 0 indicating the number is positive. The 8-bit exponent field equals 129, which is 2+127. The remaining bits are from the binary representation except for the leading one after the binary point.
 
vela said:
Negative numbers are easy if you know how to do positive numbers. You just flip the sign bit.

Floating point representation is essentially just scientific notation using base 2. To convert to base 2, first convert the integer part. Then multiply the fraction by 2. The integer part of the result is the next bit. To get successive bits, repeat the process of discarding the integer part and multiplying the resulting fraction by 2.

For example, the binary representation of 3.671875 starts with 11. After the binary point, the bits are

2x0.671875 = 1.34375
2x0.34375 = 0.6875
2x0.6875 = 1.375
2x0.375 = 0.75
2x0.75 = 1.5
2x0.5 = 1.0

So 3.671875 in decimal has the binary representation 11.1010112. Now you want to move the binary point all the way to the left, yielding 0.11101011_2\times2^2.

Just multiply it by 2? Why did you take the 0.75 from 1.375 and not 0.375?

In IEEE 754 single-precision format, you first have the sign bit, 0 for positive and 1 for negative. Add an offset of 127 to the exponent and store the result in the next 8 bits. You then drop the first bit of the mantissa, because you know it's always 1, and store the rest in the remaining 23 bits. For our example, you'd have

0 10000001 11010110000000000000000

The first bit is 0 indicating the number is positive. The 8-bit exponent field equals 129, which is 2+127. The remaining bits are from the binary representation except for the leading one after the binary point.

Thank you.
Just multiply it by 2? Why did you take the 0.75 from 1.375 and not 0.375?
 
  • #10
Take another look at what Vela wrote, starting with "Then multiply the fraction by 2. The integer part of the result is the next bit. To get successive bits, repeat the process of discarding the integer part and multiplying the resulting fraction by 2."
 
  • #11
XodoX said:
Thank you.
Just multiply it by 2?
Multiplying by 2 just shifts the binary point over by one spot (just like multiplying by 10 shifts the decimal point over by one spot), so it causes the leading bit in the fraction to become the integer part.

You could also multiply a fraction by a power of two to turn it into an integer and then find the binary representation of the integer. For example, 0.671875x26 = 43, which is represented by 1010112. So 0.671875 = 43x2-6 = 0.1010112. The main complication with this approach are that you can't turn most fractions neatly into an integer by multiplying by a power of two, so you need to choose the power of 2 to get the number of bits you want and toss the remaining part of the fraction, and then you still have to find the (possibly large) integer's binary representation.

Why did you take the 0.75 from 1.375 and not 0.375?
I think you missed the line between the 1.375 to the 0.75.
 

Similar threads

Replies
9
Views
2K
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 25 ·
Replies
25
Views
15K
Replies
6
Views
10K
  • · Replies 8 ·
Replies
8
Views
5K
Replies
10
Views
4K
Replies
11
Views
6K