The first situation .

It is necessary to convert the decimal fraction for example ( 0,65 ), in binary number system! On the example of a fraction of 0,75 everything turns out to be simple: 0,75 *2 = 1,50 * 2 = 3,00 as a result we get 0,11 - we got one, and we 0,11 stop at this! And in the example, 0,65 already more difficult ... here we get an infinite loop that can go on forever!

That is, it turns out 0,65*2 = 1,30 * 2 = 0,60 * 2 = 1,22 * 2 = 0,44 * 2 = 0,88 and then the cycle begins! Ie 1,76 -> 1,52 -> 1,04 -> 0,08 -> 0,16 -> 0,32 -> 0,64 -> 1,28 -> 0,46 -> 0,72 -> 1,44 and again it turns out 0,88 .

How to understand that we got the necessary accuracy of calculations?

And the second situation.

101101 = 1ั…2^0 + 0ั…2^1 + 1ั…2^2 + 1ั…2^3 + 0ั…2^4 + 1ั…2^5 = 0 + 2 + 4 + 8 + 32 = 46
// although it should be 45

check
46/2 = 23 -> 46 - 46 = 0
23/2 = 11 -> 23 - 22 = 1
11/2 = 5 -> 11 - 10 = 1
5/2 = 2 -> 5 - 4 = 1
2/2 = 1 -> 2 - 2 = 0
1
and it turns out 101110 completely different number!

What did I do wrong?

    2 answers 2

    In the first case, you yourself should know what the accuracy of the calculations is necessary.

    In the second case, I suggest you translate using discharges. Discharges are known to be counted from scratch. Then we look - in the number 101101 6 digits. Get

    1 * 2^5 + 0 * 2^4 + 1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 45.

    • while typing, @yozh already answered;) - NikOlia
    • with a practically identical answer :) - yozh

    With the second situation it is clear: the first term in you is not 0, but 1*2^0=1 , and the second is 0*2^1=0 . Total 45.

    On account of the first situation. I myself did not deal seriously with fractions in different number systems, but Wikipedia says that exact reduction is possible in rare cases, so you have to decide for yourself what accuracy is sufficient for you.

    • And damn ... I forgot that any number in the zero degree gives 0! Thanks, plus I canโ€™t put it yet) - Nu3oN
    • @ Nu3oN, in fact, any number in the zero degree gives 1. - NikOlia
    • Nakosyachil again - Nu3oN
    • any number except zero, of course - saigono