How to determine the base of a number in computer science. Converting numbers to binary, hexadecimal, decimal, octal number systems

  • 02.07.2020

Notation is a method of writing a number using a specified set of special characters (numbers).

Notation:

  • gives a representation of a set of numbers (integer and/or real);
  • gives each number a unique representation (or at least a standard representation);
  • displays the algebraic and arithmetic structure of a number.

Writing a number in some number system is called number code.

A single position in the display of a number is called discharge, so the position number is rank number.

The number of digits in a number is called bit depth and matches its length.

Number systems are divided into positional and non-positional. Positional number systems are divided

on the homogeneous and mixed.

octal number system, hexadecimal number system and other number systems.

Translation of number systems. Numbers can be converted from one number system to another.

Correspondence table of numbers in various systems reckoning.

Before we start solving problems, we need to understand a few simple points.

Consider the decimal number 875. The last digit of the number (5) is the remainder of the division of the number 875 by 10. The last two digits form the number 75 - this is the remainder of the division of the number 875 by 100. Similar statements are true for any number system:

The last digit of a number is the remainder of dividing that number by the base of the number system.

The last two digits of a number are the remainder of dividing the number by the base of the squared number system.

For example, . We divide 23 by the base of system 3, we get 7 and 2 in the remainder (2 is the last digit of the number in the ternary system). Divide 23 by 9 (base squared), we get 18 and 5 in the remainder (5 = ).

Let's go back to the usual decimal system. Number = 100000. 10 to the power of k is one and k zeros.

A similar statement is true for any number system:

The base of the number system to the power of k in this number system is written as a unit and k zeros.

For example, .

1. Search for the base of the number system

Example 1

In a number system with some base, the decimal number 27 is written as 30. Specify this base.

Solution:

Denote the required base x. Then .i.e. x=9.

Example 2

In a number system with some base, the decimal number 13 is written as 111. Specify this base.

Solution:

Denote the required base x. Then

We solve the quadratic equation, we get the roots 3 and -4. Since the base of the number system cannot be negative, the answer is 3.

Answer: 3

Example 3

Indicate, separated by commas, in ascending order, all the bases of the number systems in which the entry of the number 29 ends in 5.

Solution:

If in some system the number 29 ends in 5, then the number reduced by 5 (29-5=24) ends in 0. We have already said that the number ends in 0 when it is divisible without remainder by the base of the system. Those. we need to find all such numbers that are divisors of the number 24. These numbers are: 2, 3, 4, 6, 8, 12, 24. Note that in the number systems with base 2, 3, 4 there is no number 5 (and in the formulation problem, the number 29 ends in 5), so there are systems with bases: 6, 8, 12,

Answer: 6, 8, 12, 24

Example 4

Indicate, separated by commas, in ascending order, all the bases of the number systems in which the entry of the number 71 ends in 13.

Solution:

If in some system the number ends in 13, then the base of this system is at least 4 (otherwise there is no number 3).

A number reduced by 3 (71-3=68) ends in 10. That is, 68 is completely divisible by the required base of the system, and the quotient of this, when divided by the base of the system, gives a remainder of 0.

Let's write out all the integer divisors of the number 68: 2, 4, 17, 34, 68.

2 is not suitable, because the base is not less than 4. Check the rest of the divisors:

68:4 = 17; 17:4 \u003d 4 (rest 1) - suitable

68:17 = 4; 4:17 = 0 (rest 4) - not suitable

68:34 = 2; 2:17 = 0 (rest 2) - not suitable

68:68 = 1; 1:68 = 0 (rest 1) - suitable

Answer: 4, 68

2. Search for numbers by conditions

Example 5

Indicate, separated by a comma, in ascending order, all decimal numbers not exceeding 25, the notation of which in the base four number system ends in 11?

Solution:

First, let's find out what the number 25 looks like in a number system with base 4.

Those. we need to find all numbers, not greater than , whose notation ends with 11. By the rule of sequential counting in a system with base 4,
we get numbers and . We translate them into the decimal number system:

Answer: 5, 21

3. Solution of equations

Example 6

Solve the equation:

Write down the answer in ternary system (the base of the number system in the answer is not necessary to write).

Solution:

Let's convert all the numbers to the decimal number system:

The quadratic equation has roots -8 and 6. (because the base of the system cannot be negative). .

Answer: 20

4. Counting the number of ones (zeros) in the binary notation of the value of the expression

To solve this type of problem, we need to remember how addition and subtraction "in a column" works:

When adding, the bitwise summation of the digits written one under the other occurs, starting from the least significant digits. If the resulting sum of two digits is greater than or equal to the base of the number system, the remainder of dividing this amount by the base of the system is written under the summed figures, and the integer part of dividing this amount by the base of the system is added to the sum of the following digits.

When subtracting, a bit-by-bit subtraction of the digits written one under the other occurs, starting from the least significant digits. If the first digit is less than the second, we “borrow” one from the adjacent (larger) digit. The unit occupied in the current digit is equal to the base of the number system. In decimal it's 10, in binary it's 2, in ternary it's 3, and so on.

Example 7

How many units are contained in the binary notation of the value of the expression: ?

Solution:

Let's represent all the numbers of the expression as powers of two:

In binary notation, two to the power of n looks like 1 followed by n zeros. Then summing and , we get a number containing 2 units:

Now subtract 10000 from the resulting number. According to the rules of subtraction, we borrow from the next digit.

Now add 1 to the resulting number:

We see that the result has 2013+1+1=2015 units.

Number system (English numeral system or system of numeration) - a symbolic method of writing numbers, representing numbers using written characters

What is the base and base of the number system?

Definition: The base of the number system is the number of different characters or symbols that
are used to represent digits in this system.
Any basis is taken natural number- 2, 3, 4, 16, etc. That is, there is an infinite
many positional systems. For example, for the decimal system, the base is 10.

Determining the base is very easy, you just need to recalculate the number of significant digits in the system. Simply put, this is the number from which the second digit of the number begins. For example, we use the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9. There are exactly 10 of them, so the base of our number system is also 10, and the number system is called “decimal”. The above example uses the numbers 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 (auxiliary 10, 100, 1000, 10000, etc. do not count). There are also 10 main digits, and the number system is decimal.

System base is the sequence of digits used to write . In no system is there a digit equal to the base of the system.

As you can guess, how many numbers there are, there can be as many bases of number systems. But only the most convenient bases of number systems are used. Why do you think the base of the most common human number system is 10? Yes, precisely because we have 10 fingers on our hands. “But there are only five fingers on one hand,” some will say, and they will be right. The history of mankind knows examples of five-fold number systems. “And with legs - twenty fingers” - others will say, and they will also be absolutely right. That's what the Mayans thought. You can even see it in their numbers.

Decimal number system

We are all accustomed to using numbers and numbers familiar to us from childhood when counting. One, two, three, four, etc. In our everyday number system, there are only ten digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9), from which we make up any numbers. Having reached ten, we add one to the digit to the left and again start counting from zero in the rightmost digit. This number system is called decimal.

It is not difficult to guess that our ancestors chose it because the number of fingers on both hands is ten. But what other number systems are there? Was the decimal system always used, or were there others?

The history of the emergence of number systems

Before the invention of zero, special signs were used to write numbers. Each nation had its own. In ancient Rome, for example, a non-positional number system dominated.

A number system is called non-positional if the value of a digit does not depend on the place it occupies. The most advanced number systems were considered to be the number systems used in Russia and Ancient Greece.

In them, large numbers were denoted by letters, but with the addition of additional signs (1 - a, 100 - i, etc.). Another non-positional number system was the one used in ancient Babylon. In their system, the inhabitants of Babylon used a record of “two floors” and only three signs: One in the Babylonian number system for one, Ten in the Babylonian number system for ten, and Zero in the Babylonian number system for zero.

Positional number systems

Positional systems have become a step forward. Now the decimal has won everywhere, but there are other systems often used in applied sciences. An example of such a number system is the binary number system.
Binary number system

It is on it that computers and all the electronics in your home communicate. In this number system, only two digits are used: 0 and 1. You ask, why was it not possible to teach a computer to count to ten, like a person? The answer lies on the surface.

It is easy to teach a machine to distinguish between two characters: on means 1, off means 0; there is a current - 1, no current - 0. There were attempts to make machines that could distinguish a larger number of digits. But all of them turned out to be unreliable, computers always confused: either 1 came to them, or 2.

We are surrounded by many different number systems. Each of them is useful in its own area. And the answer to the question of which and when to use remains with us.

Convert to decimal number system

Exercise 1. What number in the decimal number system corresponds to the number 24 16?

Solution.

24 16 = 2 * 16 1 + 4 * 16 0 = 32 + 4 = 36

Answer. 24 16 = 36 10

Task 2. It is known that X = 12 4 + 4 5 + 101 2 . What is the number X in decimal notation?

Solution.


12 4 = 1 * 41 + 2 * 40 = 4 + 2 = 6
4 5 = 4 * 5 0 = 4
101 2 = 1 * 2 2 + 0 * 2 1 + 1 * 2 0 = 4 + 0 + 1 = 5
Find the number: X = 6 + 4 + 5 = 15

Answer. X = 15 10

Task 3. Calculate the value of the sum 10 2 + 45 8 + 10 16 in decimal notation.

Solution.

Let's translate each term into the decimal number system:
10 2 = 1 * 2 1 + 0 * 2 0 = 2
45 8 = 4 * 8 1 + 5 * 8 0 = 37
10 16 = 1 * 16 1 + 0 * 16 0 = 16
The sum is: 2 + 37 + 16 = 55

Convert to binary number system

Exercise 1. What is the number 37 in binary number system?

Solution.

You can convert by dividing by 2 and combining the remainders in reverse order.

Another way is to expand the number into the sum of powers of two, starting with the highest, the calculated result of which is less than the given number. When converting, the missing powers of a number should be replaced with zeros:

37 10 = 32 + 4 + 1 = 2 5 + 2 2 + 2 0 = 1 * 2 5 + 0 * 2 4 + 0 * 2 3 + 1 * 2 2 + 0 * 2 1 + 1 * 2 0 = 100101

Answer. 37 10 = 100101 2 .

Task 2. How many significant zeros are in the binary representation of the decimal number 73?

Solution.

We decompose the number 73 into the sum of powers of two, starting with the highest and multiplying the missing powers by zeros, and the existing ones by one:

73 10 = 64 + 8 + 1 = 2 6 + 2 3 + 2 0 = 1 * 2 6 + 0 * 2 5 + 0 * 2 4 + 1 * 2 3 + 0 * 2 2 + 0 * 2 1 + 1 * 2 0 = 1001001

Answer. There are four significant zeros in the binary notation for the decimal number 73.

Task 3. Calculate the sum of x and y for x = D2 16 , y = 37 8 . Present the result in binary number system.

Solution.

Recall that each digit of a hexadecimal number is formed by four binary digits, each digit of an octal number by three:

D2 16 = 1101 0010
37 8 = 011 111

Let's add the numbers:

11010010 11111 -------- 11110001

Answer. The sum of the numbers D2 16 and y = 37 8 , represented in the binary system, is 11110001.

Task 4. Given: a= D7 16 , b= 331 8 . Which of the numbers c, written in binary notation, meets the condition a< c < b ?

  1. 11011001
  2. 11011100
  3. 11010111
  4. 11011000

Solution.

Let's translate the numbers into the binary number system:

D7 16 = 11010111
331 8 = 11011001

The first four digits for all numbers are the same (1101). Therefore, the comparison is simplified to a comparison of the least significant four digits.

The first number in the list is the number b, therefore, does not fit.

The second number is greater than b. The third number is a.

Only the fourth number fits: 0111< 1000 < 1001.

Answer. The fourth option (11011000) meets the condition a< c < b .

Tasks for determining values ​​in various number systems and their bases

Exercise 1. The characters @, $, &, % are encoded in two-digit consecutive binary numbers. The first character corresponds to the number 00. Using these characters, the following sequence was encoded: $% [email protected]$. Decode this sequence and convert the result to hexadecimal.

Solution.

1. Let's compare the binary numbers to the characters they encode:
00 - @, 01 - $, 10 - &, 11 - %

3. Let's translate the binary number into the hexadecimal number system:
0111 1010 0001 = 7A1

Answer. 7A1 16 .

Task 2. Garden 100 x fruit trees, of which 33 x are apple trees, 22 x are pears, 16 x are plums, 17 x are cherries. What is the base of the number system (x).

Solution.

1. Note that all terms are two-digit numbers. In any number system, they can be represented as follows:
a * x 1 + b * x 0 = ax + b, where a and b are the digits of the corresponding digits of the number.
For a three digit number it would be like this:
a * x 2 + b * x 1 + c * x 0 = ax 2 + bx + c

2. The condition of the problem is as follows:
33x + 22x + 16x + 17x = 100x
Substitute the numbers in the formulas:
3x + 3 + 2x +2 + 1x + 6 + 1x + 7 = 1x 2 + 0x + 0
7x + 18 = x2

3. Solve the quadratic equation:
-x2 + 7x + 18 = 0
D \u003d 7 2 - 4 * (-1) * 18 \u003d 49 + 72 \u003d 121. Square root from D is 11.
The roots of the quadratic equation:
x = (-7 + 11) / (2 * (-1)) = -2 or x = (-7 - 11) / (2 * (-1)) = 9

4. A negative number cannot be the base of the number system. So x can only be equal to 9.

Answer. The desired base of the number system is 9.

Task 3. In a number system with some base, the decimal number 12 is written as 110. Find this base.

Solution.

First, let's write the number 110 through the formula for writing numbers in positional number systems to find the value in the decimal number system, and then find the base by brute force.

110 = 1 * x 2 + 1 * x 1 + 0 * x 0 = x 2 + x

We need to get 12. We try 2: 2 2 + 2 = 6. We try 3: 3 2 + 3 = 12.

So the base of the number system is 3.

Answer. The desired base of the number system is 3.

Task 4. In what number system would the decimal number 173 be represented as 445?

Solution.
We denote the unknown base by X. We write the following equation:
173 10 \u003d 4 * X 2 + 4 * X 1 + 5 * X 0
Given that any positive number to the zero power is equal to 1, we rewrite the equation (base 10 will not be indicated).
173 = 4*X 2 + 4*X + 5
Of course, such a quadratic equation can be solved using the discriminant, but there is a simpler solution. Subtract from the right and left parts by 4. We get
169 \u003d 4 * X 2 + 4 * X + 1 or 13 2 \u003d (2 * X + 1) 2
From here we get 2 * X + 1 \u003d 13 (we discard the negative root). Or X = 6.
Answer: 173 10 = 445 6

Tasks for finding several bases of number systems

There is a group of tasks in which it is required to list (in ascending or descending order) all bases of number systems in which the representation of a given number ends with a given digit. This task is solved quite simply. First you need to subtract the given digit from the original number. The resulting number will be the first base of the number system. And all other bases can only be divisors of this number. (This statement is proved on the basis of the rule for transferring numbers from one number system to another - see item 4). Just remember that the base of the number system cannot be less than the given digit!

Example
Indicate, separated by commas, in ascending order, all the bases of the number systems in which the entry of the number 24 ends in 3.

Solution
24 - 3 \u003d 21 is the first base (13 21 \u003d 13 * 21 1 + 3 * 21 0 \u003d 24).
21 is divisible by 3 and 7. The number 3 is not suitable, because There is no 3 in the base 3 number system.
Answer: 7, 21