Current location - Plastic Surgery and Aesthetics Network - Plastic surgery and beauty - What is the difference between "overflow" and "carry"?
What is the difference between "overflow" and "carry"?
For integers, overflow is beyond the range that the type can represent. For example, the unsigned integer 0- 1 will overflow. The signed integer-32768-16 will overflow.

There is a problem here. Generally, the CPU will not distinguish whether your operation is signed or not, because the operation method is the same whether it is signed or not. In other words, both overflows need to be considered. In order to distinguish them, the overflow of unsigned integers is called carry.

Carry judgment method: when adding and subtracting, most significant bit generates carry or borrow, which means that the result is beyond the range of unsigned number, and the single byte is 0 ~ 255;

Overflow judgment method: during addition and subtraction, only one bit of the highest and second highest order generates carry or borrow, which means that the result is beyond the signed number range, and the single byte is-128 ~127;