



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Unsigned binary addition follows the same rules as ordinary arithmetic Example: 4-bit UB carry 0 1 1 1 decimal 0 0 1 1 3 0 1 1 1 7 result 1 0 1 0 10
Two's complement addition also follows the same rules as UB Example: 4-bit 2C carry 1 1 1 1 1 0 1 1 - 0 1 1 1 7 result 0 0 1 0 2 Note that the carry from the high-order bit may be ignored.
How do we subtract? Negate the number to be subtracted and add a - b = a + (-b)
Assumption: we have enough bits to represent a value. However, a computer must work with a finite number of bits. What happens if the result doesn't fit in the available bits? This is called overflow. Result of an operation is greater than the max possible value or less than the min value. In UB: carry 1 1 1 1 decimal 1 0 1 1 11 0 1 1 1 7 result 0 0 1 0 2 What should the result be? Overflow occurs in UB when there is a carry out of the msb. (Value is too large for N bits.) What about 2C? In our example of 2C addition, there was a carry out of the msb, but the result was correct! carry 1 1 1 1 1 0 1 1 - 0 1 1 1 7 result 0 0 1 0 2 In fact, whenever we add a positive and a negative number, overflow won't occur, because the result will be less than the magnitude of the larger value. When does overflow occur in 2C? carry 1 0 1 1 1 0 1 1 - 1 0 0 1 -
UB multiplication also follows the same rules as ordinary arithmetic carry 0 1 1 1 0 0 decimal 0 1 0 1 5 0 1 1 1 7 0 1 0 1 0 1 0 1 0 1 0 1 0 0 0 0 result 0 1 0 0 0 1 1 35
Notice that the operations can be carried out using just add and shift How many bits are needed?
2C multiplication: sign bit must be extended to get proper answer carry 2 2 2 1 1 0 0 1 1 1 1 1 1 0 1 - 0 1 1 1 7 1 1 1 1 1 1 0 1 1 1 1 1 1 0 1 1 1 1 1 0 1 0 0 0 0 0 result 1 1 1 0 1 0 1 1 -
How do we carry a 2 in binary?
This document was created with Win2PDF available at http://www.daneprairie.com. The unregistered version of Win2PDF is for evaluation or non-commercial use only.