Introduction * Binary numbers are represented with a separate sign bit along with the magnitude. * For example, in an 8-bit binary number, the MSB is the sign bit and the remaining 7 bits correspond to magnitude.
Magnitude * The magnitude part contains true binary equivalent of the number for positive numbers, while 2’s complement form of the number for the negative numbers
Example + 13, 0, - 46 are represented as follows Sign Magnitude
Explanation * It is important to note that the number zero is assigned with the sign bit ‘0’. * Therefore, the range of numbers that can be represented using 8-bit binary number is -128 to * In general, the range of numbers that can be represented by n-bit number is (-2 n-1 ) to (+2 n-1 -1)
Addition in the 2’s complement system
Cases of Addition 1.When both the numbers are positive 2.When augend is a positive and addend is a negative number 3.When augend is a negative and addend is a positive number 4.When both the numbers are negative
Case 1 Two positive numbers Consider the addition of +29 and (augend) (addend) (Sum=48) Sign bit
Explanation * The sign bits of both augend and addend are zero and the sign bit of the sum=0. * It indicating that when the sum is positive they have the same number of bits.
Case 2 Positive augend Number and Negative addend Number Consider the addition of +39 and [ ]Convert to-22 [ ] Complement (augend) (addend) (Sum=17) Sign bit Carry The carry is omitted. Then result is
Explanation * The sign bit of addend is 1. * A carry is generated in the last position of addition. * This carry is always omitted. * So the final Sum is
Case 3 Positive addend Number and Negative augend Number Consider the addition of -47and [ ]Convert to-47 [ ] Complement (augend) (addend) (Sum=-18) Sign bit
Explanation * The result has a sign bit of 1, indicating a negative number. * It is in the 2’s complement form. * The last seven bits actually represent the 2’s complement of the sum.
Explanation Cont., * The true magnitude of the sum can be found by taking the 2’s complement of , the result is (+18). * Thus represents -18
Case 4 Two Negative Numbers Consider the addition of -32 and (augend) (addend) (Sum=-76) Sign bit 1 Carry The carry is discarded. Then result is
Explanation * The true magnitude of the sum is the complement of , i.e., (-76). * Thus, the 2’s complement addition works in every case. * This assumes that the decimal sum is within -128 to +127 range. Otherwise we get an overflow.
Subtraction in the 2’s complement system
Introduction * As in the case of addition, subtraction can also be carried out in four possible cases. * Subtraction by the 2’s complement system involves addition.
Case 1 Both the Numbers are positive Consider the subtraction of +19 and [ ]Convert to+19[ ] Complement Add the +28 and -19 as (Sum=9) Carry
Case 2 Positive number and smaller Negative Number Consider the subtraction of +39 and [ ]Convert to-21[ ] Complement Add the +39 and +21 as (Sum=60)
Case 3 Positive Number and Larger Negative Number Consider the subtraction of +19 and [ ]Convert to-43[ ] Complement Add the +19 and +43 as (Sum=62)
Case 4 Both the Numbers are Negative Consider the subtraction of +33 and [ ]Convert to-57[ ] Complement [ ]Convert to+33[ ] Complement Add the +33 and -57 as (Result=-24)
….... Thank You ……