introduction * binary numbers are represented with a separate sign bit along with the magnitude. *...
TRANSCRIPT
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
SignSign Magnitude
Magnitude
+3 00000 1101000 1101
0 00000 0000000 0000
-46 11010 1110010 1110
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
+127.
* In general, the range of numbers that can be
represented by n-bit number is (-2n-1) to (+2n-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 1Two positive numbers
Consider the addition of +29 and +19
+29 10111000 (augend)
+19 11001000 (addend)
00001100 (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 2Positive augend Number and Negative addend Number
Consider the addition of +39 and -22
-22 +22 [ 000 10110 ] Convert to -22 [ 111 01010]
Complement
+39 11100100 (augend)
-22 01010111 (addend)
100010001 (Sum=17)
Sign bitCarry
The carry is omitted. Then result is 0 0 0 1 0 0 0 1
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 0 0 01 0 0 0 1
Case 3Positive addend Number and Negative augend Number
Consider the addition of -47and +29
-47 +47 [ 0 01 01110] Convert to -47 [ 110 10001]
Complement
-47 10001011 (augend)
+29 10111000 (addend)
01110111 (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 1101110 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 1101110, the result is 10010 (+18).
* Thus 11101110 represents -18
Case 4Two Negative Numbers
Consider the addition of -32 and -44
-32 00000111 (augend)
-44 00101011 (addend)
00101101 (Sum=-76)
Sign bit
1
Carry
The carry is discarded. Then result is 1 0 1 1 0 1 0 0
Explanation
* The true magnitude of the sum is the complement of
0110100 , i.e., 1 0001100 (-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 1Both the Numbers are positive
Consider the subtraction of +19 and +28
+19 -19 [0001 0010] Convert to +19[ 1110 1101]
Complement
Add the +28 and -19 as
+28 00111000
+19 10110111
100100001 (Sum=9)
Carry
Case 2Positive number and smaller Negative Number
Consider the subtraction of +39 and -21
-21 +21[1110 1011] Convert to -21[0001 0101]
Complement
Add the +39 and +21 as
+39 11100100
+21 10101000
00111100 (Sum=60)
Case 3Positive Number and Larger Negative Number
Consider the subtraction of +19 and -43
-43 +43[1101 0100] Convert to -43[0010 1011]
Complement
Add the +19 and +43 as
+19 11001000
+43 11010100
11111100 (Sum=62)
Case 4Both the Numbers are Negative
Consider the subtraction of +33 and -57
-57 +57[0011 1000] Convert to -57[1100 0111]
Complement
+33 -33[1101 1111] Convert to +33[0010 0001]
Complement
Add the +33 and -57 as
-57 11100011
+33 10000100
00010111 (Result=-24)
….... Thank You ……