1. Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.
    Dismiss Notice

binary subtraction using 2's complement

Discussion in 'Mathematics and Physics' started by tejasvi, Feb 9, 2018.

  1. tejasvi

    tejasvi New Member

    Joined:
    Jun 18, 2009
    Messages:
    9
    Likes:
    0
    how do i calculate binary subtraction of 0000-0001 using 2's complement
    my calculation looks like this
    0001 >complement= 1110 > adding 0001 = 1111
    finally adding it to
    0000
    1 1 1 1
    -------
    1 1 1 1 which is wrong

    but in reverse i get correct answer
    0000 >complement= 1111 > adding 0001 = 0000
    0000
    0001
    -------
    0001 which is correct
     
  2. Ian Rogers

    Ian Rogers Super Moderator Most Helpful Member

    Joined:
    Mar 28, 2011
    Messages:
    9,517
    Likes:
    937
    Location:
    Rochdale UK
    ONLINE
    1111 is -1...

    0011 = 3
    0010 = 2
    0001 = 1
    0000 = 0
    1111 = -1
    1110 = -2
     
  3. MikeMl

    MikeMl Well-Known Member Most Helpful Member

    Joined:
    Mar 17, 2009
    Messages:
    11,260
    Likes:
    574
    Location:
    AZ 86334
    Are you asking " how do I form the twos complement of an integer?", or "how do I do subtraction using twos complement?"
     
  4. dave

    Dave New Member

    Joined:
    Jan 12, 1997
    Messages:
    -
    Likes:
    0


     
  5. Ratchit

    Ratchit Well-Known Member

    Joined:
    Mar 12, 2008
    Messages:
    1,969
    Likes:
    86

    No it's not. You don't understand 2's complement arithmetic. 1's complement arithmetic has a plus zero (0000) and a negative zero (1111). 2's complement arithmetic has only a positive zero (0000). Therefore, 1111 represents -1 decimal in 2's complement arithmetic and your answer is correct.

    Why are you puzzled when you get a positive one when you add zero to a positive one?

    Ratch
     
  6. KeepItSimpleStupid

    KeepItSimpleStupid Well-Known Member Most Helpful Member

    Joined:
    Oct 30, 2010
    Messages:
    10,023
    Likes:
    1,107
    4 bits in 2's complement would represent -8 to +7. 16 bits represents -32768 to 32767; there is only one zero in 2's complement notation.

    The left most bit is the sign bit and you can "sign extend" that. so if you had 1111 (-1) sign extended to 16 bits 1111 1111 1111 1111 is still -1.
    So is 0001 (1) sign extended to 16 bits 0000 0000 0000 0001 is still 1.
     
    • Like Like x 1

Share This Page