1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

How do I convert signed decimal to binary

  1. Sep 30, 2009 #1
    1. Convert the following numbers to 32-bit two's complement binary numbers.

    -22 , -100





    Can someone explain this to me? I thought I just convert the +22, which is 10110 and add it to all the 1's. Like,

    111111......10110 and positive would be 00000000.....10110. But that's not how it works.
     
  2. jcsd
  3. Sep 30, 2009 #2

    berkeman

    User Avatar

    Staff: Mentor

    You need to count backwards from 0000000 to 1111111 to 1111110, etc. Count with 0's for the negative numbers, not with 1's:

    http://en.wikipedia.org/wiki/2s_complement

    .
     
  4. Sep 30, 2009 #3
    I dont knwo what you mean. I don't even shave the right numbers it seem.s
     
  5. Sep 30, 2009 #4

    berkeman

    User Avatar

    Staff: Mentor

    Did you read the wiki link?
     
  6. Sep 30, 2009 #5
    Yeah, I don't get it. I read it before I posted this thread.
     
  7. Sep 30, 2009 #6
    Right, here's how it's done.

    1) You were right to convert the +ve value to binary to give 000...010110
    2) Flip the bits (every 1 becomes a 0)
    3) add 1 to the answer.

    The bit that intrigued me was the adding 1 part but if we take 0 as an example and use 8 bits then:

    0(dec) = 00000000(bin)
    flip to give 11111111(dec)
    If you don't add 1 then +0 and -0 are different so we add 1 and discard the carry to give 00000000.

    -1 would then be 11111111
    -2 becomes 11111110 and so on.

    To show the usefulness of this let's have a look at 5 - 2:

    We treat it as 5 + (-2) as you can in decimal:

    00000101
    11111110 +
    -----------
    00000011 (overfow set but ignored here)

    So there you go, a whistlestop tour of 2's complement!
     
  8. Sep 30, 2009 #7
    Thank you. So,

    0110 1100 0001 0000 would be

    0110 1100 0001 0001

    I just haver seen an example where they did it totally differently.
     
  9. Oct 1, 2009 #8
    Not quite, to save any issues on here (and make sure I'm not doing any homework) I'll use an example I'm making up:

    0011 0110 1001 0011
    1100 1001 0110 1100 - Flipped
    1100 1001 0110 1101 - With the 1 added, and that's the -ve value of 0011 0110 1001 0011 using 2's complement.
     
    Last edited: Oct 1, 2009
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: How do I convert signed decimal to binary
Loading...