Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - How to judge overflow when computer does binary addition and subtraction?
How to judge overflow when computer does binary addition and subtraction?
Signed operation overflowed. Signed operation? OF=0, which is the same as the sign operation of = 1.

Overflow, binary addition and subtraction, depends on the "highest carry" and "second highest carry".

If these two digits are the same, there is no overflow.

Let the numbers b7b6b5b4b3b2b 1b0 and a7a6a5a4a3a2a 1a0 expressed by two 8-bit complements be added,

The carry of b7+a7 is called C7, and the carry of b6+a6 is called C6.

Then, C7 and C6, if different, are overflows.

The landlord gave the following questions. According to these, it is impossible to judge overflow because there is no "second highest carry".

Overflow (b7 and a7 are symbol marks), and then _ _ _

A. The logic or result of B7 and a7 must be 1.

B. The logical sum of B7 and a7 must be 0.

C. The logical XOR result of B7 and a7 must be 1.

D. The logical XOR result of B7 and a7 must be 0; The answer is D.

Extended data:

In almost all computer languages, whether new or old, any attempt to overflow the buffer is usually automatically detected and stopped by the language itself (for example, by throwing an exception or adding more space to the buffer as needed). But two languages are not like this: C and C++. C and C++ languages usually just let extra data be written in the rest of the memory at will, which may be exploited to lead to terrible results.

To make matters worse, it is more difficult to write the correct code in C and C++ to handle the buffer overflow consistently. It is easy to accidentally cause a buffer overflow. Except that C and C++ are widely used, these may be irrelevant facts; For example, 86% of the code lines in Red Hat Linux 7. 1 are written in C or C ++. So a lot of code is vulnerable to this problem, because the implementation language can't protect the code from this problem.

Baidu encyclopedia-overflow