In the course of computer science, regardless of school or university, a special place is given to such a concept as number systems. As a rule, several lessons or practical exercises are allocated for it. The main goal is not only to learn the basic concepts of the topic, to study the types of number systems, but also to get acquainted with binary, octal and hexadecimal arithmetic.
What does that mean?
Let's start with the definition of the basic concept. As the Computer Science textbook notes, a number system is a system of writing numbers that uses a special alphabet or a specific set of numbers.
Depending on whether the value of a digit changes from its position in the number, two are distinguished: positional and non-positional number systems.
In positional systems, the value of a digit changes with its position in the number. So, if we take the number 234, then the number 4 in it means units, but if we consider the number 243, then here it will already mean tens, not units.
In non-positional systemsthe value of a digit is static, regardless of its position in the number. The most striking example is the stick system, where each unit is indicated by a dash. No matter where you assign the wand, the value of the number will only change by one.
Non-Positional Systems
Non-positional number systems include:
- A single system, which is considered one of the first. It used sticks instead of numbers. The more there were, the greater was the value of the number. You can meet an example of numbers written in this way in films where we are talking about people lost at sea, prisoners who mark every day with the help of notches on a stone or tree.
- Roman, in which Latin letters were used instead of numbers. Using them, you can write any number. At the same time, its value was determined using the sum and difference of the digits that made up the number. If there was a smaller number to the left of the digit, then the left digit was subtracted from the right one, and if the digit to the right was less than or equal to the digit to the left, then their values were summed up. For example, the number 11 was written as XI, and 9 as IX.
- Alphabetic, in which numbers were denoted using the alphabet of a particular language. One of them is considered the Slavic system, in which a number of letters had not only a phonetic, but also a numerical value.
- Babylonian number system, which used only two symbols for writing - wedges and arrows.
- Egypt also used special characters to represent numbers. When writing a number, each character could be used no more than nine times.
Positional systems
Much attention is paid in computer science to positional number systems. These include the following:
- binary;
- octal;
- decimal;
- hexadecimal;
- hexadecimal, used when counting time (for example, in a minute - 60 seconds, in an hour - 60 minutes).
Each of them has its own alphabet for writing, translation rules and arithmetic operations.
Decimal system
This system is the most familiar to us. It uses numbers from 0 to 9 to write numbers. They are also called Arabic. Depending on the position of the digit in the number, it can denote different digits - units, tens, hundreds, thousands or millions. We use it everywhere, we know the basic rules by which arithmetic operations are performed on numbers.
Binary system
One of the main number systems in computer science is binary. Its simplicity allows the computer to perform cumbersome calculations several times faster than in the decimal system.
To write numbers, only two digits are used - 0 and 1. At the same time, depending on the position of 0 or 1 in the number, its value will change.
Initially, it was with the help of binary code that computers received all the necessary information. At the same time, one meant the presence of a signal transmitted using voltage, and zero meant its absence.
Octalsystem
Another well-known computer number system in which numbers from 0 to 7 are used. It was used mainly in those areas of knowledge that are associated with digital devices. But recently it has been used much less frequently, as it has been replaced by the hexadecimal number system.
BCD
Representation of large numbers in the binary system for a person is a rather complicated process. To simplify it, a binary-decimal number system was developed. It is usually used in electronic watches, calculators. In this system, not the whole number is converted from the decimal system to binary, but each digit is translated into the corresponding set of zeros and ones in the binary system. The same goes for converting from binary to decimal. Each digit, represented as a four-digit set of zeros and ones, is converted to a digit in the decimal number system. In principle, there is nothing complicated.
To work with numbers, in this case, a table of number systems is useful, which will indicate the correspondence between numbers and their binary code.
Hexadecimal
Recently, the hexadecimal number system has become increasingly popular in programming and computer science. It uses not only numbers from 0 to 9, but also a number of Latin letters - A, B, C, D, E, F.
At the same time, each of the letters has its own meaning, so A=10, B=11, C=12 and so on. Each number is represented as a set of four characters:001F.
Number conversion: from decimal to binary
Translation in number systems occurs according to certain rules. The most common conversion from binary to decimal and vice versa.
In order to convert a number from decimal to binary, it is necessary to consistently divide it by the base of the number system, that is, the number two. In this case, the remainder of each division must be fixed. This will continue until the remainder of the division is less than or equal to one. It is best to carry out calculations in a column. Then the received remainders from the division are written to the string in reverse order.
For example, let's convert the number 9 to binary:
We divide 9, since the number is not evenly divisible, then we take the number 8, the remainder will be 9 - 1=1.
After dividing 8 by 2, we get 4. Divide it again, since the number is evenly divisible - we get the remainder 4 - 4=0.
Perform the same operation with 2. The remainder is 0.
As a result of division, we get 1.
Next, we write down all the balances we received in reverse order, starting from the division total: 1001.
Regardless of the final number system, the conversion of numbers from decimal to any other will occur according to the principle of dividing the number by the basis of the positional system.
Translate numbers: from binary to decimal
It's pretty easy to convert numbers to decimal from binary. To do this, it is enough to know the rules for raising numbers to a power. In thiscase, to a power of two.
The translation algorithm is as follows: each digit from the binary number code must be multiplied by two, and the first two will be in the power of m-1, the second - m-2 and so on, where m is the number of digits in the code. Then add the results of the addition, getting an integer.
For schoolchildren, this algorithm can be explained more simply:
First, we take and write down each digit multiplied by two, then put down the power of two from the end, starting from zero. Then add the resulting number.
For example, let's take a look at the previously obtained number 1001, converting it to the decimal system, and at the same time check the correctness of our calculations.
It will look like this:
123 + 022+021+ 120=8+0+0+1=9.
When studying this topic, it is convenient to use a table with powers of two. This will significantly reduce the amount of time required to complete the calculations.
Other translations
In some cases, translation can be carried out between binary and octal, binary and hexadecimal. In this case, you can use special tables or run the calculator application on your computer by selecting the “Programmer” option in the View tab.
Arithmetic operations
Regardless of the form in which the number is presented, it is possible to carry out the usual calculations with it. This can be division and multiplication, subtraction and addition in the number system,which you have chosen. Of course, each of them has its own rules.
So for the binary system developed its own tables for each of the operations. The same tables are used in other positional systems.
You don't have to memorize them - just print them out and have them handy. You can also use the calculator on your PC.
One of the most important topics in computer science is the number system. Knowing this topic, understanding the algorithms for transferring numbers from one system to another is a guarantee that you will be able to understand more complex topics, such as algorithmization and programming, and will be able to write your first program yourself.