Thread: two's complement question

  1. #1
    Registered User
    Join Date
    Dec 2005
    Posts
    5

    two's complement question

    I'm learning about binary and two's complement.

    I cannot replicate the result from the following problem with my current knowledge of two's complement - subtraction:

    "subtracting -5 from 15 is really adding 5 to 15, but this is hidden by the two's complement representation:"

    Code:
     11110 000   (borrow)
      0000 1111  (15)
    − 1111 1011  (−5)
    ===========
      0001 0100  (20)
    The question is: in the last 4 bits (left nibble), how can you borrow from 0 if it's 0? The example above seems to be borrowing from the next colum where the top bits are all 0's. Can someone explain how this is happening?

  2. #2
    Gawking at stupidity
    Join Date
    Jul 2004
    Location
    Oregon, USA
    Posts
    3,218
    It's the same way you borrow in base 10. If you have 48 - 55, then you'll have nothing to borrow from in the tens place. So you just add a 1 making 48 become 148.
    If you understand what you're doing, you're not learning anything.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. two's complement
    By alyeska in forum C++ Programming
    Replies: 4
    Last Post: 10-21-2007, 09:55 PM
  2. sscanf and 32 bit two's complement
    By The Urchin in forum C++ Programming
    Replies: 4
    Last Post: 10-15-2006, 02:17 AM
  3. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  4. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  5. opengl DC question
    By SAMSAM in forum Game Programming
    Replies: 6
    Last Post: 02-26-2003, 09:22 PM