Studying encodings, I realized that I didn’t understand the number system well enough. Nevertheless, he often used the 2nd, 8th, 10th, 16th systems, translated one into another, but everything was done on an “automaton”. After reading a lot of publications, I was surprised by the lack of a single, written in simple language, articles on such basic material. That is why I decided to write my own, in which I tried to explain the basics of number systems in an accessible and orderly manner.
Introduction
The number system is a way of recording (representing) numbers.
What is meant by this? For example, you see several trees in front of you. Your task is to count them. To do this, you can bend fingers, make notches on a stone (one tree - one finger \ notch) or compare 10 trees with some object, for example, a stone, and a single instance - a stick and lay them on the ground as they are counted. In the first case, the number is represented as a string of bent fingers or notches, in the second, a composition of stones and sticks, where to the left are stones, and to the right are sticks
')
Number systems are divided into positional and non-positional, and positional, in turn, into homogeneous and mixed.
Nonpositional is the most ancient, in it each digit of a number has a value that does not depend on its position (discharge). That is, if you have 5 dashes, then the number is also equal to 5, because each dash, regardless of its place in the line, corresponds to only 1 one item.
Positional system - the value of each digit depends on its position (digit) in the number. For example, the usual 10th number system is positional. Consider the number 453. The number 4 indicates the number of hundreds and corresponds to the number 400, 5 - the number of tens and similar to the value 50, and 3 - units and the value 3. As you can see - the greater the discharge - the higher the value. The total number can be represented as the sum of 400 + 50 + 3 = 453.
Homogeneous system - for all digits (positions) of a number the set of valid characters (digits) is the same. As an example, take the previously mentioned 10th system. When writing a number in a homogeneous 10th system, you can use only one digit from 0 to 9 in each digit, so the number 450 is allowed (1st digit - 0, 2nd - 5, 3rd - 4), 4F5 is not, because the F character is not included in the set of numbers from 0 to 9.
Mixed system - in each digit (position) of a number the set of valid characters (digits) may differ from the sets of other digits. A striking example is the time measurement system. There are 60 different characters in the discharge of seconds and minutes (from “00” to “59”), 24 hours in the discharge of hours (from “00” to “23”), in the discharge of days - 365, etc.
Non-positioning systems
As soon as people learned to count, there was a need to write numbers. In the beginning, everything was simple - a nick or dash on some surface corresponded to one object, for example, one fruit. So there was the first number system - the unit.
Unit number system
The number in this number system is a string of dashes (sticks), the number of which is equal to the value of this number. Thus, the harvest of 100 dates will be equal to the number consisting of 100 dashes.
But this system has obvious inconveniences - the greater the number - the longer the string of sticks. In addition, you can easily make a mistake when writing a number, by accidentally adding an extra stick or, conversely, without adding.
For convenience, people began to group sticks of 3, 5, 10 pieces. At the same time, each group corresponded to a certain sign or object. Initially, fingers were used for counting, so the first signs appeared for groups of 5 and 10 pieces (units). All this allowed us to create more convenient systems for recording numbers.
Ancient Egyptian Decimal System
In ancient Egypt, special symbols (numbers) were used to designate the numbers 1, 10, 10
2 , 10
3 , 10
4 , 10
5 , 10
6 , 10
7 . Here are some of them:

Why is it called decimal? As stated above, people began to group symbols. In Egypt, we chose a grouping of 10, leaving the number “1” unchanged. In this case, the number 10 is called the base of the decimal number system, and each character is a representation of the number 10 to some extent.
Numbers in the ancient Egyptian number system were recorded as a combination of these
characters, each of which is repeated no more than nine times. The total value was equal to the sum of the elements of the number. It is worth noting that this method of obtaining a value is peculiar to each nonpositional number system. An example is the number 345:

Babylonian sixties system
In contrast to the Egyptian, in the Babylonian system, only 2 symbols were used: a “direct” wedge - to denote units and a “recumbent” - for dozens. To determine the value of a number, it is necessary to divide the image of a number into digits from right to left. The new discharge begins with the appearance of a direct wedge after a recumbent one. As an example, take the number 32:

The number 60 and all its degrees are also denoted by a straight wedge as “1”. Therefore, the Babylonian number system was called the sixtieth.
All numbers from 1 to 59 Babylonians were recorded in the decimal nonpositional system, and large numbers in the positional with the base 60. The number 92:

The record of the number was ambiguous, since there was no digit denoting zero. The representation of the number 92 could mean not only 92 = 60 + 32, but, for example, 3632 = 3600 + 32. To determine the absolute value of a number, a special character was introduced to denote the missing sixtieth digit, which corresponds to the appearance of the digit 0 in the decimal notation:

Now the number 3632 should be written as:

The six-decimal Babylonian system is the first number system, partly based on the positional principle. This number system is used today, for example, when determining the time - an hour consists of 60 minutes, and a minute of 60 seconds.
Roman system
The Roman system is not much different from the Egyptian. It uses the capital Latin letters I, V, X, L, C, D and M, respectively, to designate the numbers 1, 5, 10, 50, 100, 500, and 1000, respectively. The number in the Roman numeral system is a set of consecutive numbers.
Methods for determining the value of a number:
- The value of a number is equal to the sum of the values of its digits. For example, the number 32 in the Roman numeral has the form XXXII = (X + X + X) + (I + I) = 30 + 2 = 32
- If to the left of the larger digit is smaller, then the value is equal to the difference between the major and minor digits. At the same time, the left digit can be less than the right maximum by one order: for example, before L (50) and C (100) of the “younger ones” there can only be X (10), before D (500) and M (1000) - only C (100), before V (5) - only I (1); the number 444 in the considered number system will be written in the form CDXLIV = (DC) + (LX) + (VI) = 400 + 40 + 4 = 444.
- The value is equal to the sum of the values of groups and numbers that do not fit the 1 and 2 points.
In addition to digital ones, there are alphabetic (alphabetic) number systems, here are some of them:
1) Slavic
2) Greek (Ionian)
Positional number systems
As mentioned above - the first prerequisites for the emergence of a positional system arose in ancient Babylon. In India, the system took the form of positional decimal numbering using zero, and the Hindus borrowed this number system from the Arabs, from whom the Europeans adopted it. For some reason, in Europe, the name “Arabic” stuck to this system.
Decimal number system
This is one of the most common number systems. That is what we use when we call the price of the goods and pronounce the number of the bus. In each digit (position) can be used only one digit from the range from 0 to 9. The base of the system is the number 10.
For example, take the number 503. If this number were written in a nonpositional system, its value would be 5 + 0 + 3 = 8. But we have a positional system and therefore each digit of the number must be multiplied by the base of the system, in this case the number “ 10 ”raised to a power equal to the digit number. It turns out that the value is 5 * 10
2 + 0 * 10
1 + 3 * 10
0 = 500 + 0 + 3 = 503. To avoid confusion when working simultaneously with several number systems, the base is indicated as a subscript. Thus, 503 = 503
10 .
In addition to the decimal system, the 2nd, 8th, and 16th systems deserve special attention.
Binary number system
This system is mainly used in computing. Why did you not use the 10th we are used to? The first computer was created by Blaise Pascal, who used her decimal system, which was inconvenient in modern electronic machines, because it required the production of devices capable of operating in 10 states, which increased their price and total dimensions of the machine. These shortcomings are devoid of elements operating in the 2nd system. However, the system in question was created long before the invention of computers and goes “roots” into the Inca civilization, where a pile was used — complex rope plexuses and knots.
Binary positional number system has a base 2 and uses to write the number 2 characters (digits): 0 and 1. In each digit only one digit is allowed - either 0 or 1.
An example is the number 101. It is similar to the number 5 in the decimal number system. In order to translate from the 2nd to the 10th, it is necessary to multiply each digit of the binary number by the base “2” raised to a power equal to the digit. Thus, the number 101
2 = 1 * 2
2 + 0 * 2
1 + 1 * 2
0 = 4 + 0 + 1 = 5
10 .
Well, for machines, the 2nd number system is more convenient, but we often see that we use numbers on the computer in the 10th system. How, then, does the machine determine which digit the user enters? How does a number transfer from one system to another, because only 2 symbols are at its disposal - 0 and 1?
In order for a computer to work with binary numbers (codes), they need to be stored somewhere. A trigger is used to store each individual digit, which is an electronic circuit. It can be in 2 states, one of which corresponds to zero, the other to unity. To memorize a single number, a register is used - a group of triggers, the number of which corresponds to the number of digits in the binary number. A set of registers - this is RAM. The number contained in the register is a machine word. Arithmetic and logical operations with words are performed by an arithmetic logic unit (ALU). To simplify access to registers they are numbered. The number is called the register address. For example, if you need to add 2 numbers - it is enough to indicate the numbers of the cells (registers) in which they are located, and not the numbers themselves. Addresses are recorded in 8 and 16 systems (they will be described below), since the transition from them to the binary system and back is quite simple. To convert from the 2nd to the 8th, it is necessary to divide into groups of 3 digits from right to left, and to go to the 16th number - by 4. If there are no digits in the leftmost group of digits, they are filled with zeros on the left, which are called leading As an example, take the number 101100
2 . In the octal one, this is 101 100 = 54
8 , and in hexadecimal - 0010 1100 = 2C
16 . Great, but why do we see decimal numbers and letters on the screen? When you press a key, a certain sequence of electrical impulses is transmitted to the computer, and each symbol has its own sequence of electrical impulses (zeros and ones). The keyboard and screen driver program accesses a code table of characters (for example, Unicode, which allows you to encode 65536 characters), determines which character corresponds to the received code, and displays it on the screen. Thus, texts and numbers are stored in computer memory in binary code, and are programmatically converted into images on the screen.
Octal numbering system
The 8th number system, like binary, is often used in digital technology. It has a base of 8 and uses numbers from 0 to 7 to write numbers.
Example of the octal number: 254. To transfer to the 10th system, each digit of the original number must be multiplied by 8
n , where n is the number of the digit. It turns out that 254
8 = 2 * 8
2 + 5 * 8
1 + 4 * 8
0 = 128 + 40 + 4 = 172
10 .
Hexadecimal system
The hexadecimal system is widely used in modern computers, for example, with the help of it the color is indicated: #FFFFFF - white. The system in question has a base of 16 and uses to write numbers: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B. C, D, E, F, where the letters are 10, 11, 12, 13, 14, 15 respectively.
As an example, take the number 4F5
16 . To convert to the octal system, first convert the hexadecimal number to binary, and then, breaking it up into groups of 3 digits, into octal. To convert a number to 2, each digit must be represented as a 4-digit binary number. 4F5
16 = (100 1111 101)
2 . But in 1 and 3 groups there is not enough discharge, so fill each with leading zeros: 0100 1111 0101. Now it is necessary to divide the resulting number into groups of 3 digits from right to left: 0100 1111 0101 = 010 011 110 101. We translate each binary group into an octal system, multiplying each digit by 2
n , where n is the digit number: (0 * 2
2 + 1 * 2
1 + 0 * 2
0 ) (0 * 2
2 + 1 * 2
1 + 1 * 2
0 ) (1 * 2
2 + 1 * 2
1 + 0 * 2
0 ) (1 * 2
2 + 0 * 2
1 + 1 * 2
0 ) = 2365
8 .
In addition to the considered positional number systems, there are others, for example:
1) Trinity
2) Quaternary
3) Twelve decimal
Positional systems are divided into homogeneous and mixed.
Uniform positional number systems
The definition given at the beginning of the article fairly fully describes homogeneous systems, so the clarification is superfluous.
Mixed number systems
We can add the following theorem to the definition already given: “if P = Q
n (P, Q, n are positive integers, and P and Q are bases), then the record of any number in the mixed (PQ) th number system identically coincides with by writing the same number in the number system with the base Q. ”
Based on the theorem, we can formulate the rules for transferring from the Pth to the Qth system and vice versa:
- To translate from Q to P, you need a number in the Qth system, divide into groups of n digits, starting with the right digit, and replace each group with a single digit in the Pth system.
- To transfer from P-th to Q-th, each digit of the number in the P-th system must be converted into Q-th and fill the missing digits with leading zeros, except for the left, so that each number in the system with base Q consists of n digits .
A vivid example is the conversion from binary to octal notation. Take the binary number 10011110
2 , to convert to octal, divide it from right to left into groups of 3 digits: 010 011 110, now multiply each digit by 2
n , where n is the digit number, 010 011 110 = (0 * 2
2 +1 * 2
1 + 0 * 2
0 ) (0 * 2
2 + 1 * 2
1 + 1 * 2
0 ) (1 * 2
2 + 1 * 2
1 + 0 * 2
0 ) = 236
8 . It turns out that 10011110
2 = 236
8 . For the uniqueness of the image of the binary-octal number, it is divided into triples: 236
8 = (10 011 110)
2-8 .
Mixed number systems are also, for example:
1) factorial
2) Fibonacci
Translation from one number system to another
Sometimes it is required to convert a number from one number system to another, therefore we will consider ways of transferring between different systems.
Convert to decimal number system
There is a number a
1 a
2 a
3 in the number system with base b. To translate into the 10th system, each digit of the number must be multiplied by
bn , where n is the number of the digit. Thus, (a
1 a
2 a
3 )
b = (a
1 * b
2 + a
2 * b
1 + a
3 * b
0 )
10 .
Example: 101
2 = 1 * 2
2 + 0 * 2
1 + 1 * 2
0 = 4 + 0 + 1 = 5
10Conversion from decimal to other
The whole part:
- We consistently divide the integer part of the decimal number by the base of the system, into which we translate, until the decimal number is zero.
- Obtained by dividing the balances are the numbers of the desired number. The number in the new system is recorded, starting with the last remainder.
Fraction:
- The fractional part of the decimal multiplied by the base of the system into which you want to transfer. Separate the whole part. We continue to multiply the fractional part of the base of the new system until it becomes equal to 0.
- The number in the new system consists of the integral parts of the results of multiplication in the order corresponding to their receipt.
Example: translate 15
10 into octal:
15 \ 8 = 1, remainder 7
1 \ 8 = 0, remainder 1
Writing down all the remains from the bottom up, we get the final number 17. Therefore, 15
10 = 17
8 .
Conversion from binary to octal and hexadecimal systems
To convert to octal, we divide the binary number into groups of 3 digits from right to left, and fill the missing extreme digits with leading zeros. Next, we transform each group by multiplying consecutive digits by 2
n , where n is the number of the digit.
As an example, take the number 1001
2 : 1001
2 = 001 001 = (0 * 2
2 + 0 * 2
1 + 1 * 2
0 ) (0 * 2
2 + 0 * 2
1 + 1 * 2
0 ) = (0+ 0 + 1) (0 + 0 + 1) = 11
8For translation into hexadecimal, we divide the binary number into groups of 4 digits from right to left, then - similarly to the conversion from the 2nd to the 8th.
Conversion from octal and hexadecimal to binary
Converting from octal to binary - we convert each digit of the octal number into a binary 3-digit number by dividing by 2 (for more information about dividing, see above “Conversion from decimal to other”) fill in the missing extreme digits with leading zeros.
For example, consider the number 45
8 : 45 = (100) (101) = 100101
2Translation from the 16th to the 2nd - we convert each digit of the hexadecimal number into a binary 4-digit number by dividing by 2, the missing extreme digits are filled with leading zeros.
Conversion of the fractional part of any number system to decimal
The conversion is performed in the same way as for integer parts, except that the digits of the number are multiplied by the base to the degree “-n”, where n starts at 1.
Example: 101,011
2 = (1 * 2
2 + 0 * 2
1 + 1 * 2
0 ), (0 * 2
-1 + 1 * 2
-2 + 1 * 2
-3 ) = (5), (0 + 0 , 25 + 0.125) = 5.375
10Conversion of the fractional part of the binary system to the 8th and 16th
The conversion of the fractional part is carried out as well as for the integer parts of a number, with the only exception that the division into groups of 3 and 4 digits goes to the right of the decimal point, the missing digits are complemented with zeros to the right.
Example: 1001.01
2 = 001 001, 010 = (0 * 2
2 + 0 * 2
1 + 1 * 2
0 ) (0 * 2
2 + 0 * 2
1 + 1 * 2
0 ), (0 * 2
2 + 1 * 2
1 + 0 * 2
0 ) = (0 + 0 + 1) (0 + 0 + 1), (0 + 2 + 0) = 11.2
8Conversion of the fractional part of the decimal system to any other
To convert the fractional part of a number to other number systems, you need to turn the integer part to zero and start multiplying the resulting number by the base of the system into which you want to translate. If, as a result of multiplication, the whole parts appear again, they must be re-turned to zero, having previously memorized (recorded) the value of the resulting whole part. The operation ends when the fractional part completely vanishes.
For example, translate 10.625
10 into a binary system:
0.625 * 2 = 1.25
0.250 * 2 = 0.5
0.5 * 2 = 1.0
Writing all the residues from top to bottom, we get 10.625
10 = (1010), (101) = 1010,101
2