Binary learning 01 (binary, hexadecimal arithmetic, data width, unsigned bit and signed bit encoding rules)


Base

The base is the carry counting system, which is an artificially defined counting method with carry (there are counting methods without carry, such as the original knot counting method, the "positive" word counting method commonly used when singing votes, and similar tally mark count). For any base-X base, it means that the number in each position is calculated every X. Decimal is one in every decimal, hexadecimal is one in every hexadecimal, binary is one in every two, and so on, and x is the one in every x.
Binary is a number system widely used by bai in computing technology. Calculation method: Binary data is a number represented by two digits, 0 and 1. Its base is 2, the carry rule is "every two enters one", and the borrow rule is "borrow one to become two".

The current computer system is basically a binary system, and data is stored in the computer in the form of complement. The binary system in a computer is a very tiny switch, using "on" to represent 1, and "off" to represent 0.


1. Introduction to Binary

Binary is a number system widely used by bai in computing technology. Calculation method: Binary data is a number represented by two digits, 0 and 1. Its base is 2, the carry rule is "every two enters one", and the borrow rule is "borrow one to become two".

The current computer system is basically a binary system, and data is stored in the computer in the form of complement. The binary system in a computer is a very tiny switch, using "on" to represent 1, and "off" to represent 0.

1) What is binary?

Binary (binary) refers to the number system based on 2 in mathematics and digital circuits, and the base 2 represents that the system is binary. In this system, it is usually represented by two different symbols, 0 (representing zero) and 1 (representing one). In digital electronic circuits, the realization of logic gates directly uses binary, so modern computers and computer-dependent devices use binary. Each number is called a bit (Bit, short for Binary digit).

2) Short form of binary

Common base conversion
Although binary has many advantages, after all, we use decimal in daily life. In order to be used in daily life, it is necessary to convert it to decimal. As for why use octal and hexadecimal? It is very simple, because it is a power of 2, 2³=8,2⁴=16, so that it is convenient for binary calculation and reading.

For other bases to convert to decimal is relatively simple, the following example illustrates: in computer science, there are abbreviations for binary, octal, decimal, and hexadecimal, so as not to confuse. Decimal system generally adds a letter D at the end [usually not to add], binary system adds a B, octal system adds Q, and hexadecimal system adds H.

Two, base operation

The essence of the base is to look up numbers, and each base is an independent system, so they can be operated independently.
Example: Write a group of octal numbers.

0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 20 21 22 23 24 25 26 27 …

2 + 3: Check 3 numbers after 2, so 2+3 = 5;

2 * 3: It can be regarded as two 3s, or 3 2s, the same reason, we can find 2*3 = 6;

4 + 5: Check 5 numbers after 4, so 4+5 = 11;

4 * 5: It can be regarded as 4 5s, or 5 4s, so we check the numbers in turn against the above table, 4*5 = 24;

1) Octal calculation table

(1) Addition table

The addition table can also be used in subtraction operations
Insert picture description here

(2) Multiplication table

Multiplication tables can also be used in division operations
Insert picture description here

(3) Simple octal calculation problems

277 + 233:
237-54:
276 * 54:
234/4:
Facing the above multiplication and addition table, list the calculation process as we learned when we were young:
Insert picture description here
Insert picture description here
Insert picture description here
Insert picture description here

Three, data width

Mathematical numbers have no size limit and can be infinitely large. But in the computer, due to hardware constraints, the data is limited in length (we call it data width). Data that exceeds the maximum width will be discarded.
No matter what data you store, it is finally stored in the form of 0, 1 in the computer.

1) What is the data width

1. Data width refers to the number of binary bits of the internal bus interconnected between the arithmetic unit and the memory in the central processing unit, which affects the throughput of the computer.

2. The data bus is responsible for the transmission of data between various components in the computer. The width of the data bus refers to the width of data transmission inside the chip.

3. The width of the data bus determines the amount of information that can be transferred at one time between the central processing unit and the secondary cache, memory, and input devices and output devices.

4. The size of the data width determines the speed of the computer.

2) Basic data width commonly used in computers

(1) Bit, also known as bit, is the smallest unit for storing, processing, and transmitting information in a computer.

(2) Byte (Byte) is the unit of measurement of binary information, which is also a bit group. A byte has 8 bits, 1Byte=8Bit.
Memory is addressed in bytes, so a byte is the smallest addressable unit.

(3) The word length is the width of the data path. It is equal to the width of the arithmetic unit, bus, and register on the physical level.

(4) The word represents the unit of processed information and is used to measure the width of the data type.
Insert picture description here
Insert picture description here

Four, unsigned number signed number

Signed numbers use the highest bit to represent the sign (positive or negative), the remaining bits represent the magnitude of the value, and unsigned numbers use all bits to represent the magnitude of the number.

Signed numbers use the highest bit as the sign bit, "0" represents "+" (positive), "1" represents "-" (negative); the rest of the digits are used as numerical bits, representing values.

1) Encoding rules for unsigned numbers:
display in hexadecimal, one hexadecimal can represent four bytes

Example:
1000 1010 is displayed as "8A"
in hexadecimal notation 0001 1011 is displayed as "1B" in hexadecimal notation

2) Signed number coding rules:
(1) Positive number coding rules: the
highest bit is "0", the coding rules are the same as unsigned numbers;
(2) Negative number coding rules: when the
highest bit is "1", we need First understand what is the original code, inverse code and complement.

Original code: The highest bit is the sign bit, and the rest are the absolute value of the value itself;

Inverse code: the inverse code of a positive number is the same as the original code; negative number: the sign bit is 1, and the remaining bits are the inverse of the original code, that is, "0" is "1", and "1" is "0";

Complement code: The complement code of a positive number is the same as the original code: Negative number: The sign bit is reversed to the original code and then adds 1.

Example: -1
Original code: 1000 0001
Inverse code: 1111 1110
Complement code: 1111 1111

Summary: In the computer, positive numbers are stored in the original code, and negative numbers are stored in the complement.

(My computer is a little white, the above content is from the Internet search, if there is an error, please correct me.)

Guess you like

Origin blog.csdn.net/Taikx/article/details/113356193