siddstuff
siddstuff

Reputation: 1255

Finding 2's complement of negative no

We assume that 4bit 2's complement system is used to represent both positive and negative numbers

Suppose  we have to find 2's complement of no.  3
We can subtract this no. with 2^4
              that is ,                   
                           = 2^4 - 3
                           = 13  
                           =1101 (which represent -3 , in 2's complement system)

//* there is another way of finding 2's complement , taking 1's complemen of the 
    number and add 1 to it.

In the book rule is given to subtract two no.

Rule : to subtract two no X and Y , that is X - Y , form 2's complement of no. Y and add it to X.

Suppose we have to subtract two no. (-7) and (-5), then according to rule, we need to find 2's complement of the no (-5), and then add it to (-7).

Book solution :

enter image description here

I need to know , how 2's complement of -5 is 0101.

Upvotes: 2

Views: 6793

Answers (1)

CraigTeegarden
CraigTeegarden

Reputation: 8251

To find the 2's complement of a number you:

  • invert the bits
  • add 1

Example (2s complement of 5):

  • 5 = 0101 in binary

  • invert the bits:

    1010

  • Add 1:

    1011 <- 2s complement of 5 is 1011

Example (2s complement of -5):

  • -5 = 1011 in binary

  • invert the bits:

    0100

  • Add 1:

    0101 <- 2s complement of -5 is 0101

Upvotes: 1

Related Questions