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
check46/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?