Computer Science XI

Binary Arithmetic

Digital arithmetic usually means binary arithmetic. Binary arithmetic can be performed using both signed and unsigned binary numbers.

Binary Addition – Unsigned numbers When two digits are added, if the result is larger than what can be contained in one digit, a carry digit is generated. For example, if we add 5 and 9, the result will be 14. Since the result cannot fit into a single digit, a carry is generated into a second digit place. When two bits are added it will produce a sum bit and a carry bit. The carry bit may be zero. Example:
0 + 0 = 0 0 0 + 1 = 0 1
carry bit sum bit 1 + 1 = 1 0 carry bit sum bit
31
The sum bit is the least significant bit (LSB) of the sum of two 1-bit binary numbers and the carry bit holds the value of carry (0 or 1) resulting from the addition of two binary numbers. Example 1: Calculate the sum of the numbers, 1100 and 1011:
1 1 0 0 1 0 1 1 ————— 1 0 1 1 1 carry bit ————— sum bits Example 2: Calculate 10111 + 10110

1 1 1 1 0 1 1 1 1 0 1 1 0 ——————— 1 0 1 1 0 1 ———————
Carry bits
In unsigned binary addition, the two operands are called augend and addend. An augend is the number in an addition operation to which another number is added. An addend is the number in an addition operation that is added to another.
2.11.2 Binary addition – signed numbers Signed addition is done in the same way as unsigned addition. The only difference is that, both operands must have the same number of magnitude bits and each must have a sign bit. As we have already seen, in a signed number, the most significant bit (MSB) is a sign bit while the rest of the bits are magnitude bits. When the number is negative, the sign bit is 1 and when the number is positive, the sign bit is 0. Example 1: Add +210 and +510. Write the operands and the sum as 4-bit signed binary
numbers.
32
+2 0 0 1 0 +5 0 1 0 1 —— ————— +7 0 1 1 1 —— ————— magnitude bits sign bit
If the result of the operation is positive, we get a positive number in ordinary binary notation. Example 2: (Use of 2’s complement in signed binary addition) Add –710 + 510 using 4-bit system. In 2’complement form, -7 is represented as follows: In binary form, 7 is represented as: 0 1 1 1 Invert the bits (1 to 0 and 0 to 1) 1 0 0 0 Add 1 1 Hence, -7 in 2’s complement form is 1 0 0 1 (-7) + 0 1 0 1 (5) —————— 1 1 1 0 (-2) —————— If the result of the operation is negative, we get a negative number in 2’s complement form. In some cases, there is a carry bit beyond the end of the word size and this is ignored. Example 3: Add -410 + 410. Use 4-bit system. 1 1 0 0 (- 4 in 2’s complement form) 0 1 0 0 (+4) —————— 1 0 0 0 0 = 0 —————— In the above example, the carry bit goes beyond the end of the word and this can be ignored. In this case both operands are having different signs. There will be no
33
error in the result. On any addition, the result may be larger than can be held in the word size being used and this would result in overflow. The overflow condition is based on the rule: If two numbers are added and if they are either positive or negative, then overflow occurs if and only if the result has the opposite sign. Example 4: Add (-710) + (-510) using the word size 4. 1 0 0 1 (-7 in 2’s complement form) 1 0 1 1 (-5 in 2’s complement form) —————— 1 0 1 0 0 (The result is wrong) —————— In the above example both operands are negative. But the MSB of the result is 0 that is the result is positive (opposite sign) and hence overflow occurs and the result is wrong. 2.11.3 Binary Subtraction Subtrahend and minuend are the two operands in an unsigned binary subtraction. The minuend is the number in a subtraction operation from which another number is subtracted. The subtrahend is the number that is subtracted from another number. Simple binary subtraction operations are as follows: 0 – 0 = 0 1 – 0 = 1 1 – 1 = 0 10 – 1 = 1 When subtracting 1 from 0, borrow 1 from the next most significant bit (MSB). When borrowing from the next most significant bit, if it is 1, replace it with 0. If the next most significant bit is 0, you must borrow from a more significant bit that contains 1 and replace it with 0 and all 0s up to that point become 1s. Example 1: Subtract 1101 – 1010
34

borrow 0 1 1 1 0 1 (minuend) - 1 0 1 0 (subtrahend) ————— 0 0 1 1 —————
When subtracting the 2nd least significant bit (1 in the subtrahend) from 0 (in the minuend), a 1 is borrowed from the more significant bit (3rd bit from right in the minuend) and hence 10 – 1 = 1. The 3rd least significant bit is made as 0. Example 2: Subtract 1000 – 101 0 1 1 after borrowing, the minuend will become 1 0 0 0 0 1 1 10 - 1 0 1 1 0 1 (subtrahend) ——— 0 0 1 1 difference as per the basic operations for subtraction ——— To subtract one number (subtrahend) from another (minuend), take the 2’s
complement of the subtrahend and add it to the minuend. Example 3: Subtract (+2) – (+7) using 4-bit system 0 0 1 0 (+2) 0 1 1 1 (+7) 1 0 0 1 ( -7 in 2’s complement form) 0 0 1 0 (2) + 1 0 0 1 (-7) —————— 1 0 1 1 (-5) —————— Example 4: Subtract (-6) – (+4) using 4 bit system Minuend - 6 1 0 1 0 2’s complement of the Subtrahend - 4 1 1 0 0 —————— 1 0 1 1 0 ——————
35
Both numbers are represented as negative numbers. While adding them, the result will be : 10110. As the word size is 4, the carry bit goes beyond the end of the word and the result is positive as the MSB is 0. This case leads to overflow and hence the result is wrong. The overflow rule works in subtraction also.

Representation of signed numbers (Prev Lesson)
(Next Lesson) Boolean algebra
Back to Computer Science XI
Notice: compact(): Undefined variable: limits in /home/bhimgautam34/public_html/wp-includes/class-wp-comment-query.php on line 853

Notice: compact(): Undefined variable: groupby in /home/bhimgautam34/public_html/wp-includes/class-wp-comment-query.php on line 853

No Comments

Post a Reply

error: Content is protected !!