how does floating point numbers get stored in memo

2020-05-10 12:19发布

as computer understands only 0's and 1's underneath,how does floating point numbers like 12.1234 gets represented in memory as a set of 0's and 1's ,

does it gets stored by respective ASCII values of 1 ,2, . ,1,2,3,4 respectively..?

2条回答
再贱就再见
2楼-- · 2020-05-10 12:43

As far as I know flaoting numbers(for single precision) are stored in memory as follows:

  • sign s (denoting whether it's positive or negative) - 1 bit
  • mantissa m (essentially the digits of your number - 24 bits
  • exponent e - 8 bits

For example:

3.14159 would be represented like this:

0 10000100 11001001000011111100111
    ^     ^               ^
    |     |               |
    |     |               +--- significand = 0.7853975
    |     |
    |     +------------------- exponent = 4
    |
    +------------------------- sign = 0 (positive)

Do note that . is not stored at all in memory.

As a good reference read What Every Computer Scientist Should Know About Floating-Point Arithmetic and Floating Point

查看更多
干净又极端
3楼-- · 2020-05-10 12:56

Since a computer understands only 0s and 1s, have you ever wondered how it can store emails, pictures, movies, sound? There are 0s and 1s stored. These are interpreted. We assign meaning to bits depending on your purposes.

Google for IEEE 754 for a thorough explanation.

查看更多
登录 后发表回答