How to transfer numbers to a binary numeral system?
my answer: “ Yes it is very simple! “. Now such subject as " occurs in each textbook of informatics; The Translation of numbers from one numeral system in another “ and the special attention is paid to binary numeral system there. But, despite the fact that as well there everything is explained very few people understand. And in this article I will try rather precisely and accurately to explain everything.
So what is numeral systems? A numeral system call a way of record of numbers by means of the set set of special signs or figures. In a binary numeral system only two such signs, are 0 and 1. The binary numeral system is used in computers. The choice of binary system is explained by the fact that electronic elements of which COMPUTERS were under construction and under construction can be only in two well distinguishable steady working conditions. In a word, these elements are presented to us as switches. And as all of us know, the switch can be included or switched off. The third is not given. One of conditions of the switch is designated 0, and another - 1.
So, we will pass directly to a subject of our article. How to transfer numbers from one numeral system to another? The developed record of binary number can look so:
A = 1 • 2^2 + 0 • 2^1 + 1 • 2^0 + 0 • 2^(-1) + 1 • 2^(-2). (^ - a degree sign). And the curtailed form of the same number looks already so: And = 101,01. Generally in binary system record of number A which contains n of the whole categories and m of fractional categories of number looks so:
A = a(n-1) • 2^ (n-1) + a(n-2) • 2^ (n-2) + … a(0) • 2^0 + a(-1) • 2^(-1)+ … a (- m) • 2^ (-m).
Coefficient of a(i) in this record are figures (0 or 1) of binary number which in the curtailed form registers so:
A = a(n-1) a(n-2) … a(0), a(-1) a (-2) a (- m).
Now I provide to your attention algorithm of the transfer of the whole decimal numbers to a binary numeral system.
Let And (tsd) - the whole decimal number. Let`s write down it in the form of the sum of degrees of the basis 2 with binary coefficients. In its record in the developed form there will be no negative degrees of the basis (number 2):
A (tsd) = a(n-1) • 2^ (n-1) + a(n-2) • 2^ (n-2) + … + (1) • 2^1 + (0) • 2^0.
On the first step we will divide number A (tsd) into foundation of binary system, that is on 2. Private from division it will be equal:
of a(n-1) • 2^ (n-2) + a(n-2) • 2^ (n-3) + … + a(1), and the rest is equal to a (0).
On the second step whole private we will divide on 2 again, the remainder of division will be equal to a (1) now.
If to continue this process of division, then after n - go a step we will receive sequence of the remains:
of a (0), (1),…, a(n-1).
It is easy to notice that their sequence coincides with the return sequence of figures of the whole binary number which is written down in the curtailed form:
of A(2) = a(n-1) … (1) a (0).
Thus, is enough to write down the remains in the return sequence to receive required binary number.
Then the algorithm will be the following:
1. It is consecutive to carry out division of initial whole decimal number and received whole private on foundation of system (on 2) until it turns out private, smaller a divider, that is less than 2.
2. To write down the received remains in the return sequence, and at the left to add the last private.
And now we will consider algorithm of the transfer of the proper decimal fractions to
a binary numeral system.
Let And (dd) - the proper decimal fraction. In its record in the developed form there will be no positive degrees of the basis (number 2):
A (dd) = a(-1) • 2^(-1) + a(-2) • 2(-2) + …
On the first step we will increase number A (dd) by foundation of binary system, that is on 2. Work will be equal:
of a (-1) + (-2) • 2^(-1) + … The whole part will be equal to a (-1).
On the second step we will increase the remained fractional part on 2 again, we will receive the whole part equal to a (-2).
The described process needs to be continued until as a result of multiplication we do not receive zero fractional part or the required accuracy of calculations will not be reached.
And here it is easy to notice that the sequence of the received numbers coincides with sequence of figures of the fractional binary number which is written down in the curtailed form: A(2) = (-1) a (-2) …
A now algorithm:
1. It is consecutive to carry out multiplication of initial decimal fraction and the received fractional parts of works by foundation of system (on 2) until the zero fractional part turns out or the required accuracy of calculations will not be reached.
2. To write down the received whole parts of work in direct sequence.
And finally it would be desirable to tell about the translation of numbers from octal and hexadecimal numeral systems in binary.
For the translation of numbers from octal and hexadecimal numeral systems in binary it is necessary to transform figures of number to groups of binary figures. For the transfer from octal system to binary each figure of number it is necessary to transform to group of three binary figures - a triad, and when transforming hexadecimal number - to group of four figures - a tetrad. And everything as you see, everything is very simple!
I hope that read my article will be able to carry out translation operations without problems as it is done by me.