Binary addition:
The rules for binary addition are the same as those for any positional number system. One adds the digits column-wise from the right. If the sum is greater than B–1 for base B, a carry into the next column is generated. In the case of binary numbers, a sum greater than one generates a carry. Here is the binary addition table:

Now we will add two binary numbers with more than one bit each so you can see how the carries “ripple” left, just as they do in decimal addition.

Binary Subtraction:
Addition has the property of being commutative, that is, a+b = b+a. This is not true of subtraction. 5 – 3 is not the same as 3 – 5. For this reason, we must be careful of the order of the operands when subtracting. We call the first operand, the number which is being diminished, the minuend; the second operand, the amount to be subtracted from the minuend, is the subtrahend. The result is called the difference.

Since we can form the complement of a binary number easily and can add signed Numbers easily, the obvious answer to the problem of subtraction is to take the two’s complement of the subtrahend, then adds add it to the minuend. We aren’t saying anything more than that 51–22 = 51+(–22).
The subtraction of two n-digit unsigned numbers M-N in base r can be done as follows:
1. Add the minuend M, to the r’s complement of the subtrahend, N.
2. If M >= N the sum will produce an end carry which can be discarded, and we left the result M-N.
3. If M < N the sum does not produce an end carry , and we have to take r’s complement of the sum and place a negative number in front.
Example:
Given the two binary numbers X=1010100 and Y=1000011, perform the subtraction (a) X – Y (b) Y – X using 2’s complements.

Therefore the answer is Y – X = -(2’s complement of 1101111) = -0010001
Related Topics : C++ Aptitude & OOPs
No comments:
Post a Comment