Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 5 years ago.
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..?
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
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.