Numeric systems
Transfer
from decimal system into a binary system
The numbers we use on a daily basis are in the form of a decimal system. We can write each decimal number in the form of another system, e.g. binary, hexadecimal, and so on. In order to transfer numbers to another system, we need to know the principle of how they work.
Numbers in a decimal system are composed of ten digits from 0 to 9. Sometimes it is also referred to as a decimal positioning system because the size that the digit represents in number entry depends on which position (place) it is in this entry . The basis of the decimal system is number 10. When naming numbers, we begin with the number zero and always add to the current value a value of one. When we get to the highest possible number (ending with number nine), we reset the number on the far right to zero and the number to the left it will be increased by one, that is, if we had number 9 (can be entered as a 09), by adding the units we get number 10, at number 89 we get 90 etc. This can be done indefinitely. Decimal numbers could be also written as a product of the number n and n-1 power of 10, e.g. number 521 could be written as follows:
52110 = 5 * 102 + 2 * 101 + 1 * 100 = 5 * 100 + 2 * 10 + 1 * 1
The binary number system is used in computing and works only with two numbers - 0 and 1. Again, we can refer it as a positional numerical system, this time with a base of two. Individual digits (0 a 1) are called bits and they are the basic units of information.
The binary system works the same as the decimal system. When we reach the highest possible number, in this case it is number one, we reset it to zero and number to the left will be increased by one. In the binary system this process is easier because we work with numbers one and zero.
Before we program a number conversion calculator between decimal and binary systems, we need to learn to count these transfers . There are two methods of converting - the method of dividing by the base and the base multiplication method.
When using the method of dividing by the base, we divide the number by the basis number into which we transfer the number (when converting to binary system we divide by the number two) until we get the quotient of zero. After each division, we write the remainder. The remainders will be either zero or one. If we list them next to each other, we get the converted number from decimal to binary, see example:
We write the rest from the bottom to the top (from the last rest until the first one). Number 215 is in binary system 11010111 (21510 = 110101112).
In the base multiplication method, we divide the number into the sum of gradually decreasing powers of two. We will always search for the largest power of number two that will be in a given number. If it is so, we will write number one, if not, we write zero. The power is then subtracted from the current value and again we find the largest power of number two in the difference of the original number and the power of two. This is how we proceed until we reach zero power of number two. The result is written as ones and twos.
Let's give an example with the number 215. The largest power of number two found in this number is 27 = 128 (28 = 256, this number is higher than our number, hence it is not in our number), we write down number one (1 * 27 ). We'll make the difference between 215 and 128, we get the number 87 and again we find the highest possible power of number two, that is 26 = 64. The occurrence is confirmed, we write down number one. Once again, we make a difference (87 - 64 = 23) and we find the next power (25 = 32). This is not in the difference, since 23 < 32, we write down zero (0 * 25). We continue as far as 20 . Mathematically, this example is written as follows:
21510 = 128 + 64 + 0 + 16 + 0 + 4 + 2 + 1 =
1 * 27 + 1 * 26 + 0 * 25 + 1 * 24 + 0 * 23 + 1 * 22 + 1 * 21 + 1 * 20 = 110101112
We can compare the results of counting using both methods and we find out that the results are the same.
Transfer from binary system into a decimal system
In the previous chapter we learned to convert numbers from the decimal system to the binary system. Now we will learn the opposite procedure, thus transfer from binary system back to the decimal system.
Unit conversion is simple. Since we know that when converting from a decimal to binary using the method of dividing by the base, we write numbers in reverse order (proceeding from last to first), we will also proceed with transfer from binary to the decimal system. The last digit of the number entered in binary system is multiplied by zero power of two. The power of the first number on the left is therefore 0, the second number has power 1, the third number has power 2 etc. Thus, the number two is increased by the number n-1, where n is the serial number on the right of the number entered in binary system. Then we calculate the results and we get the number in decimal system. For example, the mathematical notation of the conversion of 1010 written in binary system to decimal would be as follows:
10102 = 0 * 20 + 1 * 21 + 0 * 22 + 1 * 23 = 0 + 2 + 0 + 8 = 1010
Transfer from decimal system into a hexadecimal system
Numerous systems can be derived from the binary system - four, eight, six and others. Creating a numeral system with a base lower than 10 is simple and it is also easy to do the transfers with them, as we know 10 digits (0 to 9). For systems with the higher base than 10, we need to replace the missing digits with other characters, such as letters in alphabetical order.
The most well-known system with a base higher than 10 is the hexadecimal system which is mainly used by informatics and hardware engineers. The values of registers, variables and so on are written in it. The hexadecimal numeral system is a position numeral system with a base of 16. It uses digits 0 through 9 and continues with capital letters A to F which correspond to values of 10 to 15 in decimal. As with the decimal or binary system, we start with the number zero and when naming numbers, to the current value of the number is added value of one. When we get to the highest possible digit (number nine), we continue with the letters A, B, C, D, E and F. When the F value is acquired, the number (in this case the letter), which is at the far right, is reset to zero and the digit or letter to the left of it is increased by one.
When converting a decimal number to a hexadecimal system, we will proceed similarly to the transfer to a binary system. We will use the division method. This time, however, we will not divide by number two, but by number 16 (the base of the hexadecimal system is 16) until we get zero. After each division, write down the rest. We will write the remains again from the last to the first and we get the correct result of the number conversion. Warning! Since we divide by 16, the rest can be 10 to 15! Then we do not write the number but replace it with the corresponding letter of the alphabet. Here are two examples:
The result is written from bottom to top (from the last rest to the
first). Number 1568 is in hexadecimal system 620 (156810 =
62016).
The result is written back from the last remainder to the first. Number 94 is in hexadecimal system 5E (9410 = 5E16).
Transfer from hexadecimal system into a decimal system
So far, we have learned to convert numbers from decimal system into binary and vice versa, we have added a conversion from decimal to hexadecimal and we continue to transfer from the hexadecimal system back to the decimal system.
Again, we will start from our knowledge of transfer from binary system into a decimal system. This time we will increase the number 16 (the base of the hexadecimal system). In the base division method, we write the result in the reverse order (the rest is written from the last to the first), the same procedure will be used for the transfer from the hexadecimal system to the decimal system. The digit, or the value of the letter, on the last position (first position on the right) of the number entered in the hexadecimal system, multiply by the zero power of the number 16, the number to the left of it multiply by the first power of the number 16, the third in order multiply by the second power of the number 16, etc. Again, the number 16 is increased by the number n-1, where n is the serial number (we proceed from right to left) of the digit written in hexadecimal system. The final step is the sum of the results, giving us the number in decimal system. Here's how we demonstrate how to do this:
E9A16 (E = 14; 9 = 9; A = 10) = 10 * 160 + 9 * 161 + 14 * 162 = 10 + 144 + 3584 = 373810