Contacts

Representation of numbers in binary code. Binary number system Binary numbers in decimal notation

This system has a base of S = 10, but each digit is represented by a four-bit binary number called a tetrad. Usually this system Notation is used in computers when entering and outputting information. However, in some types of computers, the ALU contains special decimal arithmetic blocks that perform operations on numbers in binary decimal code. This allows in some cases to significantly increase computer performance.

For example, in automated system there is a lot of processing of numbers, but not enough calculations. In this case, operations associated with transferring numbers from one system to another would significantly exceed the time required to perform information processing operations.

Converting numbers from the decimal system to BCD is very simple and consists of replacing each digit with a binary tetrad.

Example.

Write the decimal number 572.38 (10) in the binary decimal number system.

The reverse translation is also simple: you need to divide the binary-decimal number into tetrads from the point to the left (for the integer part) and to the right (for the fractional part), add the required number of insignificant zeros, and then write each tetrad as a decimal digit.

Example.

Write the binary decimal number 10010.010101 (2-10) in the decimal number system.

Conversion of numbers from BCD to binary system is carried out according to the general rules described above.

2.3. Octal number system

In the octal number system, only eight digits are used, i.e. this number system has the base S = 8. In general view An octal number looks like this:

Where
.

The octal number system is not needed by a computer, unlike the binary system. It is convenient as a compact form of writing numbers and is used by programmers (for example, in program texts for a more concise and convenient way of writing binary codes of commands, addresses and operands). In the octal number system, the weight of each digit is a multiple of eight or one eighth, so an eight-bit binary number allows you to express decimal values ​​in the range 0-255, and an octal number covers the range 0-99999999 (for binary this is 27 digits).

Since 8=2 3, each octal character can be represented as a three-bit binary number. To convert a number from the binary number system to the octal number system, you need to divide this number to the left (for the integer part) and to the right (for the fractional part) of the point (comma) into groups of three digits (triads) and represent each group with a number in the octal number system. The extreme incomplete triads are supplemented with the required number of insignificant zeros.

Example.

Write the binary number 10101011111101 (2) in the octal number system.

Example.

Write the binary number 1011.0101 (2) in the octal number system.

Conversion from octal to binary is carried out by representing each digit of an octal number as a three-digit binary number (triad).

2.4. Hexadecimal number system

This number system has a base of S = 16. In general, a hexadecimal number looks like this:

Where
.

The hexadecimal number system makes it possible to write multi-bit binary numbers even more briefly and, in addition, to shorten the notation of a 4-bit binary number, i.e. nibble, since 16=2 4 . The hexadecimal system is also used in program texts for a more concise and convenient recording of binary numbers.

To convert a number from the binary number system to hexadecimal, you need to divide this number to the left and right of the point into tetrads and represent each tetrad with a digit in the hexadecimal number system.

Example.

Write the binary number 10101011111101 (2) in hexadecimal.

Example.

Write the binary number 11101.01111 (2) in hexadecimal.

To convert a number from the hexadecimal number system to the binary number system, it is necessary, on the contrary, to replace each digit of this number with a tetrad.

In conclusion, it should be noted that the transfer of arbitrary numbers from one number system to another can be carried out according to the general rules described in the section “ Binary system reckoning.” However, in practice, translations of numbers from the decimal system to the considered number systems and vice versa are carried out through the binary number system.

Also, remember that hexadecimal and octal numbers are only a way of representing the large binary numbers that the processor actually operates on. In this case, the hexadecimal system is preferable, since in modern computers processors manipulate words of length 4, 8, 16, 32 or 64 bits, i.e. the length of words is a multiple of 4. In the octal number system, words that are multiples of 3 bits are preferred, for example, words with a length of 12 bits (as in the PDP-8 from DEC).

The binary number system uses only two digits, 0 and 1. In other words, two is the base of the binary number system. (Similarly, the decimal system has a base of 10.)

To learn to understand numbers in the binary number system, first consider how numbers are formed in the decimal number system familiar to us.

In the decimal number system we have ten digits (from 0 to 9). When the count reaches 9, a new digit (tens) is introduced, the ones are reset to zero and the count starts again. After 19, the tens digit increases by 1, and the ones are reset to zero again. And so on. When the tens reach 9, then the third digit appears - hundreds.

The binary number system is similar to the decimal number system, except that only two digits are involved in the formation of the number: 0 and 1. As soon as the digit reaches its limit (i.e., one), a new digit appears, and the old one is reset to zero.

Let's try to count in binary system:
0 is zero
1 is one (and this is the discharge limit)
10 is two
11 is three (and that's the limit again)
100 is four
101 – five
110 – six
111 – seven, etc.

Converting numbers from binary to decimal

It is not difficult to notice that in the binary number system, the lengths of numbers increase rapidly as the values ​​increase. How to determine what this means: 10001001? Unaccustomed to this form of writing numbers human brain usually can't figure out how much it is. It would be nice to be able to convert binary numbers to decimal.

In the decimal number system, any number can be represented as a sum of units, tens, hundreds, etc. For example:

1476 = 1000 + 400 + 70 + 6

1476 = 1 * 10 3 + 4 * 10 2 + 7 * 10 1 + 6 * 10 0

Look at this entry carefully. Here the numbers 1, 4, 7 and 6 are a set of numbers that make up the number 1476. All these numbers are multiplied in turn by ten raised to one degree or another. Ten is the base of the decimal number system. The power to which ten is raised is the digit of the digit minus one.

Any binary number can be expanded similarly. Only the base here will be 2:

10001001 = 1*2 7 + 0*2 6 + 0*2 5 + 0*2 4 + 1*2 3 + 0*2 2 + 0*2 1 + 1*2 0

1*2 7 + 0*2 6 + 0*2 5 + 0*2 4 + 1*2 3 + 0*2 2 + 0*2 1 + 1*2 0 = 128 + 0 + 0 + 0 + 8 + 0 + 0 + 1 = 137

Those. the number 10001001 in base 2 is equal to the number 137 in base 10. You can write it like this:

10001001 2 = 137 10

Why is the binary number system so common?

The fact is that the binary number system is a language computer technology. Each number must be somehow represented on a physical medium. If this is a decimal system, then you will have to create a device that can have ten states. It's complicated. It is easier to produce a physical element that can only be in two states (for example, there is current or no current). This is one of the main reasons why so much attention is paid to the binary number system.

Converting a decimal number to binary

You may need to convert the decimal number to binary. One way is to divide by two and form a binary number from the remainder. For example, you need to get its binary notation from the number 77:

77 / 2 = 38 (1 remainder)
38 / 2 = 19 (0 remainder)
19 / 2 = 9 (1 remainder)
9 / 2 = 4 (1 remainder)
4 / 2 = 2 (0 remainder)
2 / 2 = 1 (0 remainder)
1 / 2 = 0 (1 remainder)

We collect the remainders together, starting from the end: 1001101. This is the number 77 in binary representation. Let's check:

1001101 = 1*2 6 + 0*2 5 + 0*2 4 + 1*2 3 + 1*2 2 + 0*2 1 + 1*2 0 = 64 + 0 + 0 + 8 + 4 + 0 + 1 = 77

(Methodological development)

Task: Convert numbers expressed in decimal form to binary form, then multiply.

Note: The rules for multiplication are exactly the same as in the decimal number system.

Multiply: 5 × 5 = 25

Converting the decimal number 5 to binary

5: 2 = 2 remainder 1 Result obtained

2: 2 = 1 remainder 0 written in reverse

1: 2 = 0 remainder 1 order

Thus: 5 (10) = 101 (2)

Converting the decimal number 25 to binary

25: 2 = 12 remainder 1

12: 2 = 6 remainder 0 Result obtained

6: 2 = 3 remainder 0 written in reverse

3: 2 = 1 remainder 1 order

1: 2 = 0 remainder 1

Thus: 11001 (2) = 25 (10)

We check:

We perform binary multiplication

×
101
+
101

The rules of multiplication in the binary system are exactly the same as in the decimal number system.

1) 1 × 1, will be 1, write 1.

2) 1 × 0, will be 0, write 0.

3) 1 × 1, will be 1, write 1.

4) We write down three zeros, with the first zero under the second sign (zero).

5) Multiplying 1 × 101 is exactly the same as p.p. 1, 2, 3.

We perform the addition operation.

6) We demolish and write down 1.

7) 0 +0 will be zero, write 0.

8) 1 + 1 will be 10, write zero, and move one to the most significant digit.

9) 0 + 0 + 1 will be 1, write 1

10) Demolish and record 1.

Task 1: Perform multiplication in binary form

Task: Convert numbers, expressions in decimal form, into binary form, then perform division.

Note: The division rules are exactly the same as in the decimal number system.

If the result is divisible without a remainder, write – 0, otherwise (with a remainder) – 1

Divide: 10:2 = 5

Convert the decimal number 10 to binary:

10:2 = 5 remainder 0 5:2 = 2 remainder 1 2:2 = 1 remainder 0 1:2 = 0 remainder 1

Result

write it backwards

Thus: 1010 (2) = 10 (10)

Converting decimal 2 to binary

2:2 = 1 remainder 0

1:2 = 0 remainder 1



Thus: 10 (2) = 2 (10)

Converting decimal 5 to binary

5:2 = 2 remainder 1

2:2 = 1 remainder 0

1:2 = 0 remainder 1

Thus: 101 (2) = 5 (10)

We check:

1010 (2) = 0×2 0 + 1×2 1 + 0×2 2 + 1×2 3 = 0 +2+0+8 =10 (10)

10 (2) = 0×2 0 +1×2 1 = 0 +2 = 2 (10)

101 (2) = 1×2 0 +0×2 1 +1×2 2 = 1+ 0+4 = 5 (10)

We perform binary division:

1010 (2) : 10 (2) = 101 (2)

1010 (2) 10
10

The division rules in the binary system are exactly the same as in the decimal system.

1) divide 10 by 10. Take 1 at a time, write 1 as the result.

2) We take down 1 (one), it’s not enough, we take 0 (zero).

3) Take 1 at a time. Subtract 10 from 10 (ten) and you get zero, which corresponds to
reality.

Task 1: Perform division in binary form

1) 10010 (2) : 110 (2) =

11000 (2) : 110 (2) =

2) 110110 (2) : 110 (2) =

Task 2: Restore the result in decimal form.

Task: Subtract numbers expressed in binary form, restore the resulting result to decimal form.

Subtract: 1100 (2) – 110 (2) =

Subtraction rules in binary form.

Subtraction in binary is similar to subtraction in decimal.

110 0 + 0 = 0

110 0 + 1 = 1

1) 0 plus 0 equals 0 (See the rules for adding numbers).

2) 1 plus 1 equals 10. We write zero and move one to the most significant digit, as in the decimal system

3) 1 plus 1 plus 1 equals 11 – a binary number. We write down 1 and the second one
transferred to the senior rank. We get: 1100 (2), which is true.

Task: Check the result obtained.

1100 (2) = 0×2 0 + 0×2 1 +1×2 2 +1×2 3 = 0 + 0 + 4 + 8 = 12 (10)

110 (2) = 0×2 0 +1×2 1 +1×2 2 = 0 + 2 + 4 = 6 (10)

Thus, we get: 6 + 6 = 12, which is true.

Do it yourself:

Task 1. Perform subtraction in binary form:

+
1010 10 (10)

110 6 (10)

10000 corresponds to: 16 (10)

The actions are performed as follows.

1) 0 plus 0 equals O

2) 1 plus 1 equals 10 (which is 2 (two) represented as 10 in binary);
Historically, ten fingers were used to add numbers and vice versa:

9 + 1 = 10; 8 + 2 = 10; 1 + 9 = 10; 2 + 8 = 10.

That's why the decimal number system came about. And in binary there are 2 (two) characters: 1 and 0

3) 1 plus 0 plus 1 equals 10. Write 0 and carry over 1.

4) 1 plus 1 equals 10, since this is last action, we write 10, we did it in the same way in the decimal system.

Task: Check the result obtained:

110

The concept of a mixed number system

Among number systems there is a class of so-called mixed number systems.

Definition 1

Mixed it's called this notation, in which numbers specified in a certain number system with base $P$ are represented using digits of another number system with base $Q$, where $Q

Moreover, in such a number system, in order to avoid discrepancies in the representation of each digit of the system with the base $P$, the same number of digits of the system with the base $Q$ is allocated, sufficient to represent any digit of the system with the base $P$.

An example of a mixed number system is the binary-decimal system.

Practical rationale for using the binary decimal number system

Since a person widely uses the decimal number system in his practice, and a computer typically operates with binary numbers and binary arithmetic, a compromise option was introduced into practice - binary decimal notation system, which is typically used where there is a need to frequently use the decimal I/O procedure (for example, Digital Watch, calculators, etc.). IN similar devices It is not always advisable to use universal microcode for converting binary numbers to decimal numbers and vice versa due to the small amount of program memory.

Note 1

In some types of computers, arithmetic logic units (ALUs) contain special decimal arithmetic units that perform operations on numbers represented in binary decimal code. This allows in some cases to significantly increase computer performance.

For example, an automated data processing system uses a large number of numbers, but not many calculations. In such a case, the operations of transferring numbers from one system to another would significantly exceed the time required to perform information processing operations. Microprocessors, on the other hand, use pure binary numbers, but they also understand commands to convert to binary decimal notation. The ALU of the AVR microcontroller (as well as other microprocessors) performs elementary arithmetic and logical operations over numbers represented in binary code, namely:

    reads the results of ADC conversion;

    in integer or floating-point format, processes measurement results.

However, the final result is displayed on the indicator in a decimal format that is convenient for human perception.

Principles of constructing a binary-decimal number system

When constructing a binary-decimal number system, $4$ binary digits are allocated to represent each decimal digit, since the maximum decimal digit $9$ is encoded as $10012$.

For example: $925_(10) = 1001 0010 0101_(2-10)$.

Picture 1.

In this notation, successive quadruples of binary digits represent the digits $9$, $2$ and $5$ of decimal notation, respectively.

To write a number in the binary-decimal number system, it must first be represented in the decimal system, and then each decimal digit included in the number must be represented in the binary system. At the same time, different numbers of binary digits are required to write different decimal digits in the binary number system. To avoid the use of any delimiters, when representing a decimal digit in binary, 4 binary digits are always written. The group of these four digits is called notebook.

Although BCD notation uses only the digits $0$ and $1$, it is different from the binary representation of a given number because the decimal equivalent of a binary number is several times larger than the decimal equivalent of a BCD number.

For example:

$1001 0010 0101_{(2)} = 2341_{(10)}$,

$1001 0010 0101_{(2)} = 925_{(2-10)}$.

This notation is quite often used as an intermediate step when converting a number from the decimal system to binary and vice versa. Since the number $10$ is not an exact power of the number $2$, not all $16$ tetrads are used (tetrads representing numbers from $A$ to $F$ are discarded, since these numbers are considered forbidden), but algorithms for arithmetic operations on multi-digit numbers in this case, more complex than in basic number systems. And yet, the binary decimal number system is used even at this level in many microcalculators and some computers.

To correct the results of arithmetic operations on numbers represented in binary decimal code, microprocessor technology uses commands that convert the results of operations into the binary decimal number system. The following rule is used: when a number greater than $9$ is obtained as a result of an operation (addition or subtraction) in a tetrad, the number $6$ is added to this tetrad.

For example: $75+18=$93.

$10001101\(8D)$

The forbidden digit $D$ appeared in the low notebook. Add $6$ to the low tetrad and get:

$10010011 \ (93)$

As you can see, despite the fact that the addition was carried out in the binary number system, the result of the operation was obtained in the binary-decimal number system.

Note 2

Bitwise balancing is often carried out based on binary decimal number system. The use of binary and binary-decimal number systems is most appropriate, since in this case the number of balancing cycles is the smallest among other number systems. Note that the use of binary code allows us to reduce the processing time of the compensating voltage by approximately $20\%$ compared to binary-decimal code.

Benefits of using the binary decimal number system

Converting numbers from the decimal system to the binary-decimal system is not associated with calculations and is easy to implement using the simplest electronic circuits, since a small number (4) of binary digits are converted. The reverse conversion occurs automatically in the computer using a special translation program.

The use of the binary-decimal number system in conjunction with one of the main number systems (binary) makes it possible to develop and create high-performance computers, since the use of a decimal arithmetic block in the ALU eliminates the need for programmed conversion of numbers from one number system to another when solving problems.

Since two binary decimal digits make up $1$ byte, which can be used to represent the values ​​of numbers from $0$ to $99$, and not from $0$ to $255$, as with an $8$-bit binary number, then using $1$ byte for By converting every two decimal digits, you can form BCD numbers with any desired number of decimal places.

Addition of positive numbers Addition of multi-digit numbers is carried out according to the rules of binary arithmetic; the peculiarity appears when two units are added. At S= The 10(10) sum of two units is two, which is equivalent to 10(2). Thus, instead of one digit, two are formed. In that...
(Computer Engineering)
  • Arithmetic operations on floating point numbers
    Adding numbers When adding floating point numbers, the result is determined as the sum of the mantissas of the terms with a common order for the terms. If the signs of both mantissas are the same, then they are added in direct codes, if different - in complement or reverse codes. In table 2.8 shows the procedure...
    (Computer Engineering)
  • Numbers in the decimal system
    10° - unit 109 - billion 1024 - septillion 101 - ten 1012 - trillion 1027 - octillion 102 - one hundred 1015 - quadrillion Yu30 - nonillion 103 - thousand 1018 - quintillion 1033 - decillion 106 - million 1021 - ...
    (Physics)
  • Number systems
    Since ancient times, people had to count various objects and write down their quantities. For these purposes there was unary a recording system in which numbers were denoted by the corresponding number of dashes (or serifs). For example, the number 5 was represented as 111 |. Unary notation is very cumbersome and...
    (Computer architecture)
  • Economy of the number system
    Number in the number system rivers digits will obviously have the greatest meaning if all digits of the number turn out to be maximum, i.e. equal (R- 1). Then (gr)tah =(/>-1)...(/>-!) = / -1. To digits The number of digits of a number when moving from one number system...
    (Computer architecture)
  • Correction of dead reckoning along one line of position
    When approaching the coast, the situation may develop in such a way that the navigator has the opportunity to obtain only one line of position. For example, a mountain top has opened up to which only a bearing can be measured, or signals from only one radio beacon are being listened to. The same situation arises when determining...
    (Analysis and processing of navigation measurements)
  • Did you like the article? Share it