MATLAB: How binary floating point to real decimal number representation

[matlab][math][logic]MATLAB

Hi, :
I'm sorry, if ask the wrong question, actually I don't know which domain it is, just know it's about math, logic, programming, which Matlab plays a very important part in the world.
My question is , in computer domain, there are floating point, eg: single/double precision floating point, which store variables in [sign, exponent, significand] format sized in [1, 11, 52] bits (for 64 bit precision double type) , refer to https://en.wikipedia.org/wiki/Double-precision_floating-point_format
How do those floating number stored in computer (normally, binary format) to represent in decimal (with fractional number , between 0 ~ 1), especially, those numbers been right of the '.' (radix).
For example, a floating number in binary, 1.111111 is in decimal = 1.9844, how do the computer represent the .9844 to us ? From many docs, they all say, it's ' 2^-1 + 2^-2 +…+ 2^-6', but that's not what I want to ask, it's most likely I am curious about how do the computer translate 0.5 + 0.25 + …. + 0.0156, in computer, they are binary, only 010101…, so when they do arithmetic, they are based on 0,1,0,1…, so that definitely won't really recognize the decimal, '0.5', '0.25', …,etc, but when we do those simple directives in Matlab, bin2dec(), f_b2d, it quickly gives the answers, I am interested in 'who' do those binary to 'decimal-string-output' task, in which level ? compiler ? What's the domain talking about those domain ?
Thank you very much.
Best regards.

Best Answer

Yes, as Stephen said, be careful about the difference between binary numbers and IEEE storage. You can easily see the IEEE representation of a double number in matlab with:
>> n = 1.9844
>> dec2bin(typecast(n, 'uint64'), 64); %typecast to uint64 doesn't change the bits, so we can extract the bit pattern
ans =
'0011111111111111110000000001101000110110111000101110101100011100'
As for your question, the computer is never aware of the decimal representation of the number, and doesn't care about it. All math is done with the binary representation. Which is why people sometimes are surprised by the result they get (see why 0.3-0.2-0.1 is not 0) because the binary math differs from the decima math. It's only for display to the user/programmer that the numbers are converted to their textual decimal representation. This is done by well established code routine, if you want to know more search for the source code of fprintf (in C). Similarly, the textual decimal representation of numbers you enter is immediately converted to the binary representation.