in Digital Logic recategorized by
127 views
1 vote
1 vote
Represent +42 and -42 in sign-magnitude, 1’s complement and 2’s complement

representation. Find the result of 42 - 20 using 2’s complement.
in Digital Logic recategorized by
127 views

1 comment

How many bits are allowed to store an integer in 1’s complement ,2’s complement ,signed-magnitude ?
0
0

1 Answer

1 vote
1 vote

Consider that we have 8 bits to represent the number. The binary representation of $42$ is $00101010$.

  1. In sign-magnitude form, the MSB is used to represent the sign bit and remaining bits represent the magnitude. So $+42$ is represented as:
0 0 1 0 1 0 1 0

and $-42$ is represented as:

1 0 1 0 1 0 1 0

 

  1. In 1’s complement form:
    1. If the number is +ve, convert it to binary and make its length to the given bit size. +42 is represented as $\textbf{00101010}$.
    2. If the number is -ve, the representation is simply the 1’s complement of that number. So the 1’s complement representation of $00101010$ is :
1 1 0 1 0 1 0 1

 

  1. In 2’s complement form:
    1. If the number is +ve, convert it to binary and make its length to the given bit size. +42 is represented as $\textbf{00101010}$.
    2. If the number is -ve, the representation is simply the 2’s complement of that number. So the 2’s complement representation of $00101010$ is : 

       (1’s complement of 00101010) + 1= (11010101 + 1) =

1 1 0 1 0 1 1 0

 

Note: If the number is +ve: sign-magnitude, 1’s complement and 2’s complement representation are all same.


 

To perform the subtraction $42 – 20$ in 2’s complement , we simply add 42 with 2’s complement of 20.

$42 – 20 = 00101010 + 2’s(00010100) = 00101010 + (11101100) = 1 00010110$.

  1. If the resultant has a carry, the answer is +ve and we discard the carry.
  2. If the resultant has no carry, the answer is -ve and to get the final value, we simply find the 2’s complement of the answer.

In this case, we have a carry, so just discard it. Value becomes $+(00010110)_2 = \textbf{+22}$

edited by