1.3 arithmetic and logical operations

Source: Internet
Author: User

1. arithmetic operation points

(1) shift operation

① Original code shift: the original code does not change the form of the original code when performing arithmetic shift left or arithmetic shift right. Shifts one digit to the left is equal to multiplying by 2, and shifts one digit to the right is equal to dividing by 2, and the vacancy caused by the shift is supplemented by 0. This is because the absolute value of the original code and the binary number is exactly the same, and the arithmetic shift does not involve the number symbol.

② Complement shift: Because the positive complement is the same as the original code, the empty complement 0 in the left and right shifts of the positive complement will not change the complement form. It is worth noting that the shift of the negative complement code, when the negative complement code shifts right, the vacant space must be filled with 1 to ensure that the value is correct and the shape is maintained.

③ Reverse code shift: Because the positive anticode is the same as the original code, the positive anticode shifts one to the left, which is equal to multiplying by 2. The left shifting result is 0. The right shifting result is equal to dividing by 2, fill in 0 for the right shift. The inverse code of a negative number shifts one digit to the left by 2, and the one to the right by 2, but the left and right shifts must fill in 1.

(2) normalized numbers under different codes

A floating point number is composed of the order code and the ending number of The number. If the ending number of the order number is, the standard of the floating point normalization number is. This requirement of normalized number is defined by the true value of the ending number, that is, the absolute value of the ending number must be greater than or equal to (equivalent to the binary number ).

The normalized number of positive numbers. No matter which encoding type is used, the maximum number of ending numbers is 1. the maximum number of negative numbers is 0 except the original code.

(3) overflow judgment

Fixed-point operations and floating-point operations all experience overflow, because operations in the computer are performed in a limited space. When the calculation result is greater than the maximum allowed space, overflow may occur. If the calculation result is smaller than the minimum value allowed by the space, overflow may occur. The computer calls the overflow value machine infinity and the overflow value machine zero.

Floating Point Numbers are composed of the order and the ending number. The overflow of floating point operations is determined by the result order, when the order of the calculation result is greater than or less than the maximum or minimum allowed by the computer, overflow or underflow occurs. Since the order of a floating point number is a positive number of a fixed point and is an index of 2, it is determined that the floating point operation can be given by the value indicated by the order.

Fixed-point addition and subtraction use the complement sum Operation Method to Determine the overflow in the operation. One is to use the carry value, and the other is to use the symbol state. Carry overflow checks whether the carry of the highest digit of the tail is the same as the carry of the sign. If the carry is the same, it indicates that there is no overflow. If the carry is different, it indicates that there is an overflow.

The combination of two symbols determines whether the overflow exists. The two symbols are in four states: 00, 01, 10, and 11. When the combination status is 01 or 10, the Operation overflows.

(4) Rounding and error

Given the operation space limit, rounding is inevitable during the operation, and rounding will inevitably lead to errors. Therefore, how to minimize the error caused by rounding is one of the problems of grasping the operation results. The size of the error is analyzed to ensure the accuracy of the calculation results.

For an n + 1 bitwise operation result of 0.100000001, placing it in an N-bit unit will inevitably produce an error due to tail truncation. This error is called a truncation error.

Rounding is usually used to improve the accuracy of calculation results and reduce errors. There are two common Rounding Methods. One is "0 homes 1 in", that is, if the discarded bit is 1, it is 1 in the previous one; if the discarded bit is 0, it is not 1.

Another round-robin processing method is to take the "constant 1" method, that is, no matter what value is rounded off, it is at the lowest position of the tail number 1.

There are two ways to analyze the error: one is to calculate the absolute error and the other is to calculate the relative error.

2. Key Points of logical operation

Logical operations include basic logical operations and compound logical operations. There are three basic logical operations: And, or, and not. Compound logical operations include and or, and non-operation, and or non-operation, exclusive OR, and same or. Logical operations can be used to establish logical variables and logical expressions of logical functions to describe and portray logical relationships and solve actual logic problems. Both basic and composite logical operations are provided by logical independent variables and logical function expressions based on measurements. If A and B are logical independent variables and F are logical functions, the logical relationship is shown in Table 1-15.

An important tool for logical operations is the truth table, which lists the values of logical variables and logical functions in one table. Because one independent variable has two values: 0 and 1, two independent variables have a combination of values, and three independent variables have a combination of values, the truth table corresponding to the function expressions of the two variables is four rows, the truth table of the three independent variables is 8 rows, and the truth table of the N independent variables is rows.

As a tool for logical operations, a truth table can also prove the relationship between two functions. If the two functions have the same truth table, the two functions are equal. The truth table values of the original function and the inverse function are usually the opposite.

To better simplify logical expressions, you can master the basic logical relationship, logical theorem, and law. Simplifying logical expressions is an important part of logical circuit design.

Logical operations come from practice, which can guide practice. With logical operations, you can complete various application problems. In addition to designing Logical Circuits, you can solve many logical problems in production and life, it also supports data processing, code conversion, and code conversion. Examples of applications are as follows.

① Logical truncation: when used and computed, you can extract part of the information from known information by selecting an appropriate logical constant. For example, you can separate the number of points from the ending number and intercept the floating point level code.

② Code Conversion: using an exclusive or same-or operation, you can select an appropriate logical constant to convert the original code into an inverse code and change the complement code into a shift code.

③ Code Conversion: using the or operation, you can select the appropriate logical constant to set the value to 0 ~ The BCD code of 9 is converted into the ASCII code of the character. You can use and perform operations to convert character numbers into numbers. For example, convert '9' to a value 9.

In addition, you can use logical operations to obtain the absolute values of negative numbers, determine the product or operator symbols, and construct odd and even verification codes.

Difficulties

1. Arithmetic Operations

1) Overview

In addition, subtraction, multiplication, division, and other operations on a computer, operations in different environments and operations in different forms lead to many new problems in operations, it also shows the following new features:

First, due to the limitation of the computing space, errors may occur in the operation. For example, in an 8-bit computing space, if a 9-digit computing result is obtained, a truncation error is generated because one bit is lost, which affects the accuracy of the result.

Second, when the computing space is constant, the range of space capacity is also limited. Once a computation result is too large or too small, it will overreach the border and cause an overflow problem, which will lead to a "interruption" calculation problem.

Third, in the computer, the number involved in the calculation is the binary number. The left and right shifts of the calculator can be used to conveniently perform multiplication and division operations.

Fourth, because the number has multiple forms, such as the original code, the reverse code, the complement code, and the transfer code, according to the characteristics of different codes, common arithmetic operations include the complement addition, the subtraction operation, the original code multiplication, and the division operation. There are fixed-point operations and floating-point operations in the form of numbers. However, no matter which type of operation, you need to consider the symbol problem of the operation result and the overflow judgment problem in the operation.

2) addition and subtraction

(1) Calculation Method

The subtraction operation can be converted into addition operations by introducing the complement code. You can combine addition and subtraction into addition by using the complement sum calculation method. This method is applicable to fixed-point decimal and fixed-point integer calculation. The method for calculating the complement sum is as follows:

Addition:

Subtraction:

(2) method for determining Overflow

By using the state combination of two carry values in the operation, overflow can be determined. It indicates the carry of the tail number to the symbol bit at a high position. If it is the carry of the symbol bit in the operation, the overflow judgment is shown in Table 1-18.

3) addition and subtraction of deformation code

The addition and subtraction operations using the deformation Supplementary Code are the sum of the two numbers of deformation supplementary codes (which is called the double symbol operation). The addition and subtraction operations are also unified into addition, the final calculation result is the deformation complement sum. After the operation, use the status of two symbols to determine whether the operation is normal.

4) one-digit multiplication of the original code (p57)

5) one-digit division of the original code (P58)

6) addition and subtraction of Floating Point Numbers

Floating Point Numbers are composed of the order code and the ending number. The addition and subtraction operations of floating point numbers only need to calculate the ending number of two operands. Before an operation, the order code of the second number must be equal by adding or subtracting the tail number. To normalize the operation results, the results after addition and subtraction must be normalized. In a limited operating space for addition and subtraction and left and right shift, the problem of low position removal may occur. In order to ensure the accuracy of the calculation results, you need to consider which round processing is used in the operation. In addition, it is also important to determine whether results out of bounds and overflow occurs in operations. To sum up, the addition and subtraction operations of floating point numbers need to be performed, such as order calculation, tail calculation, normalization, rounding processing, and overflow judgment.

7) multiplication and division of Floating Point Numbers

① Floating-point multiplication: two floating-point numbers are multiplied, the ending number is multiplied, and the order code is added. The product symbol is obtained by the difference or of the two operand symbols. During the multiplication process, you also need to process rounding, determine overflow, and normalize the product.

② Floating-point Division: two floating-point numbers are divided. The ending number of the quotient is generated by the ending number of the devisor divided by the ending number of the devisor. The order code of the quotient is obtained by the order code of the devisor, the operator's symbol is determined by the result of the two-operand symbol "exclusive or.

2. logical operations

1) logical operation Overview

Logical operations are performed on binary variables. binary variables refer to variables with only 0 and 1 values.

2) basic logical operations

(1) Operation

It describes the problem that two or more parallel conditions determine whether a thing is true or not. For example, if two series switches control an electric lamp, the light and the light off depend on the status of the two switches. If the toggle is set to 1, the toggle is set to 0, the light is set to 1, and the light is set to 0, the problem of two series switches controlling an electric lamp becomes a problem of Two-value variable operations. Because the two switches have a combination of four states, the electric lights controlled by the switch generate two results: "bright" and "not bright, so we can use two variables to describe the status of two switches and one electric lamp, and use a table to display the status of two switches and one electric lamp. This table is called a truth table.

"Operator" and "•" are operators for operations. They can be omitted in writing. To sum up the above calculation rules, we can use a single sentence: "The two ends are 1 at the same time, and the result is 1; otherwise, it is 0", that is, only when the two ends of the operator are 1 at the same time, the result is 1. The rule of Operation accurately expresses the logical relationship that a thing can establish only when two parallel conditions are established at the same time.

This operation has the function of "intercepting information". To intercept information, you must use an appropriate logical constant. This logical constant is set to 1, the information bit that is not intercepted is set to 0. This constant is called a "logical ruler ". The logic ruler of operations can freely separate information and intercept information. It is an important tool for information processing.

(2) or operation

Or operations describe the logical relationship between two or more conditions that determine whether a thing is true. When one of the conditions is true, a thing can be established. For example, two parallel switches control one electric lamp. If one of them is switched on, the bright thing of the electric lamp is the basis of the or operation. Like Analysis and Computation, the switch is regarded as an independent variable, and the lamp is regarded as a function. The two switches have four combined states, respectively acting on the lamp, make it produce two results: Bright and not bright. The correspondence between the Independent Variables and functions is listed as a table, which is the truth table of the or operation.

"Operator" and "+" are operators for the or operation. Or the operation rule can also be summarized as one sentence, that is, "1 is 1, otherwise it is 0 ".

(3) Non-Calculation

Non-computation describes the objective reality in which a condition is established rather than true when the condition is established. It indicates that "1 is available, not 0 ". The algorithm is: when y = 1, that is, f = 0; when y = 0, that is, F = 1.

3) logical operations

The rule of the XOR operation can be summarized as one sentence: "the difference is 1, otherwise it is 0", and the same or operation is: "The same is 1, otherwise it is 0 ".

4) basic logical relationship

There are two logical constants in Logical Algebra, namely, 0 and 1. Logical constants have the following basic relationships with any logical variable (assumed as;

These basic relationships are tools for simplifying logical expressions.

5) Law of Logical Algebra

Logical Algebra also has many laws like ordinary algebra, which can be used to transform and simplify logical expressions. Each logical expression can be proved by using a truth table, that is, the left and right sides of the equation are listed in the truth table. If the truth table is the same, the expression is equal.

(1) Exchange Law

(2) law of association

(3) allocation Law

(4) Overlapping Law

(5) absorption law

(6) Inclusion Law

(7) De Morgan's Theorem

6) logic expression simplification

Logical expressions are the basis of Logical Circuits. Simplifying logical expressions is equivalent to simplifying Logical Circuits. Simplifying Logical Circuits not only saves components, but also improves the running speed of logical circuits.

Using basic logical relationships and Logical Algebra law to simplify logical expressions is called the algebraic simplification method. The Algebraic simplification method combines, deletes, and absorbs all items in a logical expression based on the basic relationship and law to form a and or expression, and minimizes the number of items in the expression and the number of variables. Reducing the number of items is equivalent to reducing the components in the logical circuit, and reducing the variable is equivalent to reducing the input.

It is not easy to master the logic expression simplification. The biggest confusion encountered is that it is unclear whether the logic expression has reached the minimum level.

The basic idea of the geometric simplification method is to regard any logical variable as a straight line in the Cartesian coordinate system. The two variables correspond to two vertical intersecting lines, and the intersection point is the two variables and the relationship. Set two logical variables A and B. Their corresponding straight lines can form a plane.

The geometric simplification operation is to first find the corresponding point on the geometric map according to the items in the function expression, and then check whether the two points are in the same line. If they are in the same line, they can be simplified, otherwise, it cannot be simplified. If four straight lines can form a plane, they can be simplified again. That is to say, the simplification step is from point to line, and then from line to plane. For items that cannot find the corresponding point, you can use the configuration item method to change to the standard type before simplifying. This method can compare with the ry to get the simplification result at a glance and determine whether the function expression is the simplest.

7) logical expression Creation

Any logical expression represents a logical relationship, which is ultimately the relationship between logical independent variables and logical dependent variables. To solve the actual logic problem, you can also use the truth table and the minimum theorem to create a logical expression.

In Logical Algebra, the items that can make the function 1 are called the smallest items, and any logical function can be written as the smallest item or.

To sum up the above analysis, we can summarize the process of establishing a logical function expression for logical problems into four steps:

① Raise a logic question and determine logical variables and functions.

② Deploy the truth table as required.

③ Write the least or function expression based on the truth table.

④ Simplify the function expression.

References:

[1] Liu kewu. Software Designer Examination Subject 1: computer and software engineering knowledge-test site analysis and simulation training [M]. Beijing: Tsinghua University Press, 2005.1.

1.3 arithmetic and logical operations

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.