Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

2's Complement Arithmetic

  1. Feb 2, 2004 #1
    How do you do this problem?

    Sum of +17.5 (Base 10) and -43.25 (Base 10) using 2's complement arithmetic.
    Difference of +17.5 (Base 10) and -43.25 (Base 10) using 2's complement arithmetic.

    The binary representations must have 12 digits. How the heck do I solve a problem with decimals like this? Thanks for any assistance.
     
  2. jcsd
  3. Feb 3, 2004 #2
    ok, some quick thoughts....
    1) first represent the numbers 17.5 and 43.25 in usual binary format. The integer part can be represented by 6 bits + 1 sign bit, and the fractional part can be represented by 2 bits, so you'll need a total of 9 bits. The remaining 12 - 9 = 3 bits can be put either on the ineger or on the fractional part of the number....
    2) transform the 2 binary numbers you've obtained in 2's complement
    3) add, respectively subtract
    4) reconvert the result in normal binary form, and then to decimal, see if you've got the correct result
     
  4. Feb 3, 2004 #3

    uart

    User Avatar
    Science Advisor

    Easy, just stick in a (fixed) "decimal" point two digits from the left and then use ordinary two's complement. (like just ingnore the "decimal point" and it will work anyway).

    Example (5 bit = xxx.xx)

    3.5 = 011.10

    -3.5 = 2's_comp(3.5) = 1000.00 - 011.10
    = 100.10

    Now lets test -3.5 in some computations.

    3.5 + (-3.5) =
    ____011.10 +
    ____100.10
    =(1)000.00 As expected



    3.75 + (-3.5) =
    ____011.11 +
    ____100.10
    =(1)000.01 As expected



    2.5 + (-3.5) =
    _010.10 +
    _100.10
    =111.00 This is (-1.00) as expected

    Note that 2's_comp(111.00) = 1000.00 - 111.00 = 001.00
     
    Last edited: Feb 3, 2004
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: 2's Complement Arithmetic
  1. Tertiary Arithmetics (Replies: 1)

  2. Modular arithmetic (Replies: 5)

  3. Arithmetic progression (Replies: 2)

  4. Arithmetic Sequence (Replies: 4)

  5. Modular arithmetic (Replies: 7)

Loading...