CSAPP notes (Chapter II representation and processing of information) -02

Overview

The second half of this chapter speak binary integer (the original code and complement) of four operations, as well as four floating-point arithmetic.

Binary integer arithmetic four

2 binary addition and subtraction of w bits, the range of results requires w + 1 bits to store, the actual median is fixed, result exceeds the range expressed by w-bit "spillover", the computer needs to deal with this "Overflow "I called the main content of this section.

Addition and Subtraction

  • w-bit unsigned adder may cause an overflow, such as overflow, \ (X + _ ^ {w} {U} Y = X + Y - 2 ^ {w} \) (overflow removing the most significant bit).
  • w-bit unsigned subtraction may cause negative, such negative result = result + 2 ^ w
  • w-bit signed addition or subtraction may cause an overflow, overflow \ (2 ^ {w} + \) (or \ (- 2 ^ {w} \) ), so as to fall \ ([- 2 ^ {w -1}, 2 ^ {w- 1} -1] \) in the range (overflow removing the most significant bit).

multiplication

  • w-bit unsigned and signed number multiplication, bitwise multiplied, the result is retained position 2w, w bits high removed, the result is the
  • Due to very slow multiply instruction (10 clock cycles or more), thus decomposition of the multiplier 2 and a plurality of power, the shift operation into a multiplication, improve processing speed

division

  • Divided by the number of symbols without using a long division, the result is rounded down, in addition to countless remainder discarded.
  • Signed divided by the number, the divisor is a positive number, the use of long division, the result is rounded down, the dividend is the same as the case of the positive unsigned number, when a negative dividend case, biased (biasing).
  • The divisor is a power of 2, as a special case, can be displaced alternatively, improve processing speed. Note that biased.

Float

Guess you like

Origin www.cnblogs.com/winwink/p/11519889.html