5 in hexadecimal system. Hexadecimal and binary number systems

The hexadecimal number system has an alphabet of 16 digits:

0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, b, c, d, e, f.

When writing a number in a hexadecimal system, the letters A, B, C, D, E, F are used to write the numbers denoting the numbers 10, 11, 12. 13, 14. 15, respectively.

Converting numbers from hexadecimal to decimal

You can convert any hexadecimal number to decimal using the already known formula

Examples.

    AE07 16 \u003d 10 ∙ 16 3 + 14 ∙ 16 2 + 0 ∙ 16 1 + 7 ∙ 16 0 \u003d 44551 10.

    100 16 =1∙16 2 +0∙16 1 +0∙16 0 =256 10 .

    58 16 =5∙16 1 +8∙16 0 =.88 10 .

    2A 16 \u003d 2 ∙ 16 1 + 10 ∙ 16 0 \u003d 42 10.

Converting a number from decimal to hexadecimal is carried out in the same way as in binary.

Converting numbers from hexadecimal to binary and vice versa

You can convert any hexadecimal number to binary as follows. Each digit of the hexadecimal notation of a number is written in a four-digit binary number - notebook... After that, the zeros on the left can be discarded.

2) 2A \u003d 0010 1010 2 \u003d 101010 2.

3) 58 16 = 0101 1000 2 = 1011000 2 .

Conversely, you can convert any binary number to hexadecimal in the same way. Every four binary digits, counting from right to left, are written in one hexadecimal digit. These numbers are also located from right to left.

Examples.

2.101010 2 \u003d 10 1010 2 \u003d 2A.

3. 1011000 2 = 101 1000 2 = 58 16 .

Octal number system

The octal number system has an alphabet consisting of 8 digits:

0, 1, 2, 3, 4, 5, 6, 7.

Converting a number from decimal to octal and vice versa is carried out by analogy with converting to binary / from binary.

Converting numbers from octal to binary and vice versa

Each digit of the octal representation of a number is written in a three-digit binary number - triad.

Examples.

2563 8 = 010 101 110 011 2 =10101110011 2 .

1001101 2 = 001 001 101 2 = 115 8 .

Methodical materials for laboratory class No. 1

Lab topic: Number systems. Measuring information.

Number of hours: 2.

Examples with solutions

    Translation fromp -ary system to 10-ary. Let it be necessary to convert a number in a certain number system to decimal. To do this, you need to represent it in the form

11100110 2 = 1∙2 7 + 1∙2 6 + 1∙2 5 + 0∙2 4 + 0∙2 3 + 1∙2 2 + 1∙2 1 + 0∙2 0 = 128 + 64 + 32 + 4 + 2 = 230 10 .

2401 5 = 2∙5 3 + 4∙5 2 + 0∙5 1 + 1∙5 0 = 250 + 100 + 0 + 1 = 351.

    Transfer from 10-ary system top -ichny.

2.1 98 10 → X 2.

Divide the number by 2. Then divide the incomplete quotient by 2. Continue until the incomplete quotient becomes less than 2, i.e. equal to 1.

    98: 2 \u003d 49. The remainder is 0 .

    49: 2 \u003d 24. The remainder is 1 .

    24: 2 \u003d 12. Remainder - 0 .

    12: 2 \u003d 6. Remainder - 0 .

    6: 2 \u003d 3. Remainder - 0 .

    3: 2 = 1 ... Remaining - 1 .

Since the last incomplete quotient is 1, the process is over. We write all the remainders from bottom to top, starting with the last incomplete quotient, and we get the number 1100010. So 98 10 \u003d 1100010 2.

2.2 2391 10 → X 16.

Divide the number by 16. Then divide the incomplete quotient by 16. Continue until the incomplete quotient is less than 16.

    2391: 16 \u003d 149. The remainder is 7 .

    149: 16 = 9 ... Remaining - 5 .

Since the last incomplete quotient (9) is less than 16, the process is over. We write, starting from the last incomplete quotient, all the remainders from bottom to top and we get the number 957. So 2391 10 \u003d 957 16.

2.3 12165 10 → X 2.

If translated by division into a binary system, then you get a rather cumbersome process. You can first convert the number to the octal system, and then replace the octal digits from right to left with triads.

12165 10 = 27605 8 = 010 111 110 000 101 = 10111110000101.

    Determining the base of the number systemp .

One boy wrote about himself: “I have 24 fingers, 5 on each hand, and 12 on my feet”. How can this be?

Decision. It is necessary to determine the base of the number system p... Since we know that there are only 10 10 toes, then 12 p =1∙p+2 \u003d 10 10. From this we obtain the equation p + 2 = 10  p \u003d 8. So the boy was referring to numbers in the octal system. Indeed, there are 24 8 fingers in total \u003d 2 ∙ 8 + 4 \u003d 20 10, and on the legs - 12 8 \u003d 1 ∙ 8 + 2 \u003d 10 10.

0123456789ABCDEF. Taking the number 16 as the base, we get the hexadecimal number system. Here we can use 10 digits of the decimal system, adding 6 more characters - letters of the Latin alphabet (A, B, C, D, E, F): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 , A, B, C, D, E, F 10 11 12 13 14 15 A total of 16 different characters make up the alphabet of the hexadecimal number system. You can write any number including all these signs: A37, 1B45, F302, 1A3C5 ... - note: we use signs from 0 to F. For the hexadecimal number system q \u003d 16. Content.

Slide 32 from presentation "History of counting and number systems"... The size of the archive with the presentation is 2292 KB.

Informatics grade 9

summary other presentations

"Modeling" Grade 9 "- Modeling as a method of cognition. File system PC. The test is over. Ptolemy built a model of the world. Human model in the form of a child's doll. The most convenient way to describe the trajectory of an object is to use information model... The existing attributes of the object. Description of the tree. It is most convenient to use the information model. List of deputies of the State Duma. List of school students; classroom plan.

"History of counting and number systems" - The base of the number system. Dozens. Decimal number. Slavic Cyrillic numbering. Numbering. Lotus flower. The position of a digit in a number is called a place. Digit position. In ancient times, people walked barefoot. The positional number system is characterized by its base. Division by base. Writing numbers of a new type. Multiplication of binary numbers. Decimal number conversion. Arithmetic operations.

"Sort in spreadsheets" - Sort and search data in spreadsheets... Data search in ET. The order of the nested sort. The Department. Record search terms. Write down the names. Practical work... Sort Ascending. The order of the lines. Sorting and searching data. Salary and age. Reflective screen. Sorting data. Select sample databases. Sorting records. Difference between record and field. How to use the autofilter.

"Cyclic programs" - Create a program. Find the amount. Please enter an integer. Find the number of three-digit natural numbers. Find the sum of natural numbers. Calculate. Loop with postcondition. Print a table on the screen. An initial fee. Loop with precondition. Dividers. Cyclic programs. Informatics. Tabulation function. Cycle concept. Loop with parameter. Input of initial data. Dollar conversion table. Find the number of numbers.

"Modeling as a method of scientific knowledge" - Table of the "objects-objects-one" type. Descriptions of the object. The method of cognition of the surrounding world. Solving problems. Educational resources... Five guys. Formalization. Stages of modeling. Boy. Hierarchical model. Description of the simulation object. Yura. Lilac. Server designations. Technical models. Layered charts. Diagram. A type. Modeling as a method of cognition. Graph models. Problems solved using graphs.

"What is Email" - Address email... Mail routing. Letter. How email works. X-mailer. The issue of the emergence of e-mail. Date. Copy. Email... The structure of the letter. Email history. Sender. Email.

Hexadecimal number system. Our first program.

To write programs in Assembler, you need to understand the hexadecimal number system. There is nothing complicated about it. We use the decimal system in life. I'm sure you all know it, so I'll try to explain the hexadecimal system by analogy with decimal.

So, in the decimal system, if we add zero to any number on the right, then this number will increase 10 times. For example: 1 x 10 \u003d 10; 10 x 10 \u003d 100; 100 x 10 \u003d 1000, etc. In this system, we use numbers from 0 to 9, i.e. ten different digits (in fact, that's why it is called decimal).

In the hexadecimal system, we use sixteen "digits" respectively. I specially wrote the word "digits" in quotation marks, because it uses more than numbers. And indeed how so? I explain: we count from 0 to 9 in the same way as in decimal, but then it will be like this: A, B, C, D, E, F. The number F, however difficult count, it will be equal to 15 in decimal system (see table. 1).

Decimal number

Hexadecimal number

Table 1. Decimal and Hexadecimal Systems.

Thus, if we add zero to the right to any number in the hexadecimal system, then this number will increase by16 time.

Example 1: 1 x 16 \u003d 10; 10 x 16 \u003d 100; 100 x 16 \u003d 1000, etc.

Were you able to distinguish between hexadecimal and decimal numbers in Example 1? And from this row: 10, 12, 45, 64, 12, 8, 19? It can be either hexadecimal or decimal. In order to avoid confusion, and the computer could uniquely distinguish some numbers from others, it is customary in Assembler to put the character h or H after a hexadecimal number ( H is an abbreviation for English. hexadecimal (hexadecimal). For brevity, it is sometimes called simply Hex ) . And after the decimal place do not put anything. Because numbers from 0 to 9 in both systems have the same values, then the numbers written as 5 and 5h are the same.

So Example 1 (see above) would be more correct to write as follows: 1 x 16 \u003d 10h; 10h x 16 \u003d 100h; 100h x 16 \u003d 1000h. Or like this: 1h x 10h \u003d 10h; 10h x 10h \u003d 100h; 100h x 10h \u003d 1000h.

What the hexadecimal system is for will be discussed in future releases. At the moment, for our example program, which will be discussed below, we need to know about the existence of hexadecimal numbers.

So, let's summarize. The hexadecimal number system consists of 10 digits (from 0 to 9) and 6 letters of the Latin alphabet (A, B, C, D, E, F). If we add zero to the right to any number in the hexadecimal system, then this number will increase by16 time. It is very important to understand this topic , since we will use it constantly when writing programs.

Now a little about how I will build examples in Assembler. It is not very convenient to bring them in HTML-format, so first there will be the program code itself with numbered lines, and immediately after it there will be explanations and notes.

More or less like this:

strings Program code
(1) mov ah, 9

Explanations:

In line (1) we do this, and in line (15) we do this.

Huge request: DO NOT copy programs from the page to the clipboard and then paste them into Notepad (or elsewhere)! Retype them by hand in a text editor. If you have a printer, then select the program, print the selected fragment, and then transfer it to the editor from paper. You need to type all the examples yourself! This will speed up the memorization of operators.

And further. Lowercase and UPPERCASE letters are not distinguished in Assembler. Records of the form:

They are perceived the same way by the assembler. You can, of course, force the Assembler to distinguish between lowercase and UPPERCASE characters, but we will not do that yet. For readability of the program, it is best to type statements lowercase letters, and the names of subroutines and labels begin with an uppercase. But this is how anyone will be comfortable.

So let's move on to our first program:

(1) CSEG segment

(2) org 100h

(4) Begin:

(6) mov ah, 9

(7) mov dx, offset Message

(8) int 21h

(10) int 20h

(11)

(12) Message db "Hello, world! $"

(13) CSEG ends

(14) end Begin

We need multiple editions to explain all of the statements in this example. Therefore, we will simply omit the description of some commands at this stage. Just consider that it should be so. In the very near future, we will consider these operators in detail. So, you simply ignore lines with numbers (1), (2) and (13).

Lines (3), (5), (9) and (11) remain blank. This is done for clarity. The assembler will just omit them.

Now let's move on to considering the rest of the operators. Line (4) starts the program code. This is a label that points the Assembler to the beginning of the code. Line (14) contains the end Begin (Begin eng. Start; end end). This is the end of the program. In general, instead of a wordBegin could have used something else. For instance,Start :. In this case, we would have to end the program.End Start (14).

Lines (6) (8) display the message Hello, world !. Here we will have to briefly talk about processor registers (we will look at this topic in more detail in the next release).

A processor register is a specially designated memory for storing a number.

For instance:

If we want to add two numbers, then in mathematics we write it like this:

A, B and C these are a kind of registers (if we talk about a computer) in which some data can be stored. A \u003d 5 can be read as: Give A the number 5 .

To assign a value to a register, there is a mov operator in Assembler (from the English move to load). Line (6) should be read like this: Load into the register AHnumber 9 (in other words, we assign AHnumber 9). Below we will consider why this is necessary.

In line (7) we load into the registerDX message address for output (in this example this will be the lineHello, world! $).

Interrupts will be discussed in detail in subsequent releases. Here I will say a few words.

Interrupt MS-DOS it is a kind of subroutine (part MS-DOS), which is permanently in memory and can be called at any time from any program.

Consider the above using an example (select the notes in small print):

Adding two numbers

StartPrograms

A \u003d 5 into the variable A we enter the value 5

B \u003d 8 to variable B value 8

CallRoutines Addition

now C is 13

A \u003d 10 the same, only different numbers

B \u003d 25

CallRoutines Addition

now C is 35

End of the program

Subroutine Addition

C \u003d A + B

ReturnFromRoutines we return to the place from which they called

EndRoutines

In this example, we called the subroutine twice Additionwhich added the two numbers passed to it in variablesA and B ... The result is placed in variable C. When a subroutine is called, the computer remembers where it was called from, and then when the subroutine has finished running, the computer returns to the place from where it was called. So you can call subroutines an indefinite number of times from anywhere.

When we execute line (8) in an Assembler program, we call a subroutine (in this case called an interrupt) that prints the string to the screen. For this, we, in fact, put the necessary values \u200b\u200bin registers. The whole necessary work (line output, cursor movement) is taken over by the subroutine. This line can be read like this: call the twenty-first interrupt (int from English. interrupt interrupt). Please note that there is a letter after 21h ... This, as we already know, is a hexadecimal number (33 in decimal). Of course, nothing prevents us from replacing the line int 21h to int 33. The program will work correctly. It's just that in Assembler it is customary to indicate the interrupt number in hexadecimal system.

In line (10), you guessed it, we call interrupt 20h ... To call this interrupt, you do not need to specify any values \u200b\u200bin the registers. It does only one thing: exit the program (exit to DOS). As a result of the execution of interrupt 20h, the program will return to the place from where it was started (loaded, called). For example, inNorton Commander or DOS Navigator.

Line (12) contains the message to display. First word (message message) message title. It can be anything (for example,mess or string, etc.). ABOUT take a look at line (7), where we load into the registerDX our message address.

We can create another line, which we will callMess2. Then, starting at line (9), insert the following commands:

(10) mov dx, offset Mess2

(13) Message db "Hello, world! $"

(14) Mess2 db "It's Me! $"

and reassemble our program. Hope you guessed what will happen

Pay attention to the last character in the linesMessage and Mess2 - $. It points to the end of the line. If we remove it, then 21h the interrupt will continue to output until it encounters a character somewhere in memory $. On the screen we will see rubbish .

If you have a debugger, you can see how our program will work.

The purpose of this issue was not to understand in detail with each operator... This is impossible, because you don't have enough knowledge yet. I believe that after 3-4 issues you will understand the principle and structure of an Assembler program. Maybe you found the assembly language extremely difficult, but believe me, this is at first glance.

Anyone who communicates with a computer or other digital equipment has come across mysterious records like 10FEF, which seem to the uninitiated with some kind of cipher. What is behind these symbols? It turns out these are just numbers. Those using hexadecimal

Number systems

Every schoolchild knows, or at least heard somewhere that all the numbers that we usually use form this name she wears simply because there are only ten different characters in it (from 0 to 9). Any number in our familiar system can be written with their help. However, it turns out that it is not always convenient to use it. For example, when exchanging information between digital devices, it is easiest to use a number system in which there are only two digits: "0" - no signal - or "1" - there is a signal (voltage or something else). It's called binary. However, in order to describe the processes inside such devices with its help, it will be necessary to perform records that are too long and difficult to understand. Therefore, the hexadecimal number system was invented.

Hexadecimal system concept

Why then for digital devices is it a system that contains sixteen different characters? As you know, information in computers is transmitted in the form of bytes, which usually contain 8 bits. A unit of data - a machine word - includes 2 bytes, that is, 16 bits. Thus, using sixteen different symbols, you can describe the information that is the smallest particle in the exchange. The hexadecimal number system includes our usual numbers (of course, from 0 to 9), as well as the first letters (A, B, C, D, E, F). It is with the help of these symbols that it is customary to write down any unit of information. Any arithmetic operations can be performed with them. That is, addition, subtraction, multiplication, division. The result will also be a hexadecimal number.

Where is applied

The hexadecimal system is used to write error codes. They can occur when various software products... For example, this is how errors are encoded operating system... Each number is standard. You can find out what kind of error occurred during the work by decrypting it using the instructions. Such symbols are also used when writing programs in low-level languages \u200b\u200bsuch as assembler. The hexadecimal number system is loved by programmers also because its components can be very easily translated into binary, which are "native" for all digital technology. Color schemes are also described using such symbols. In addition, absolutely all files on the computer (both text and graphic, and even music or video) are presented after the broadcast in the form of a sequence. Viewing the original is most convenient just in the form of hexadecimal characters.

Of course, any number can be written in different systems reckoning. This is decimal, binary, and hexadecimal. To translate a word from one of them to another, you should use a service such as a number system translator, or do it yourself using a certain algorithm.

To represent numbers in a microprocessor, use binary number system.
Moreover, any digital signal can have two stable states: " high level"And" low level ". In the binary system, two numbers are used to represent any number, respectively: 0 and 1. An arbitrary number x \u003d a n a n-1 ..a 1 a 0, a -1 a -2… a -m will be written in the binary system as

x \u003d an 2 n + a n-1 2 n-1 +… + a 1 2 1 + a 0 2 0 + a -1 2 -1 + a -2 2 -2 +… + a -m 2 -m

where a i - binary digits (0 or 1).

Octal number system

In the octal system, the base digits are the digits from 0 to 7. The 8 least significant units are combined into the most significant one.

Hexadecimal number system

In hexadecimal notation, the base digits are numbers from 0 to 15, inclusive. To designate basic digits more than 9 in one character, in addition to the Arabic numerals 0 ... 9, the letters of the Latin alphabet are used in the hexadecimal number system:

10 10 \u003d A 16 12 10 \u003d C 16 14 10 \u003d E 16
11 10 \u003d B 16 13 10 \u003d D 16 15 10 \u003d F 16.

For example, the number 175 10 in hexadecimal notation will be written as AF 16. Really,

10 16 1 + 15 16 0 \u003d 160 + 15 \u003d 175

The table shows numbers from 0 to 16 in decimal, binary, octal and hexadecimal notation systems.

Decimal Binary Octal Hexadecimal
0 0 0 0
1 1 1 1
2 10 2 2
3 11 3 3
4 100 4 4
5 101 5 5
6 110 6 6
7 111 7 7
8 1000 10 8
9 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
16 10000 20 10

Binary to Octal and Binary to Hexadecimal Conversions

The binary number system is convenient for performing arithmetic operations with the hardware of the microprocessor, but it is inconvenient for human perception, since it requires a large number of bits. Therefore, in computer technology, in addition to the binary number system, octal and hexadecimal number systems are widely used for a more compact representation of numbers.

The three-bit octal number system implements all possible combinations of octal digits in the binary number system: from 0 (000) to 7 (111). To convert a binary number to octal, you need to combine the binary digits into groups of 3 bits (triads) in two directions, starting from the decimal separator. If necessary, add non-significant zeros to the left of the original number. If the number contains a fractional part, then insignificant zeros can also be added to the right of it until all triads are filled. Then each triad is replaced by an octal digit.

Example: Convert 1101110.01 2 to octal.

We combine binary digits into triads from right to left. We get

001 101 110,010 2 = 156,2 8 .

To convert a number from octal to binary, you need to write each octal digit in binary code:

156,2 8 = 001 101 110,010 2 .

The four-bit hexadecimal number system implements all possible combinations of hexadecimal digits in binary notation: from 0 (0000) to F (1111). To convert a binary number to hexadecimal, you need to combine binary digits in groups of 4 digits (tetrads) in two directions, starting from the decimal separator. If necessary, add non-significant zeros to the left of the original number. If the number contains a fractional part, then to the right of it, you also need to add insignificant zeros until all the notebooks are filled. Then each notebook is replaced with a hexadecimal digit.

Example: Convert 1101110.11 2 to hexadecimal notation.

We combine binary numbers into tetrads from right to left. We get

0110 1110.1100 2 \u003d 6E, C 16.

To convert a number from hexadecimal to binary, you need to write each hexadecimal digit in binary code.

Did you like the article? To share with friends: