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

Confusion with 1's and 2's complement

  1. Apr 30, 2009 #1
    Thanks visiting this thread.

    I am a college student.

    I have a little confusion with these complements. Of course i know that in '+' and '-' 2's complement is used but is it limited to only '-' and '+'.

    What are the places in which the 1's complement is used and what is the reason for not using the 2's complement there.

    And finally why do we have 2 kinds of complements in the first place.
  2. jcsd
  3. Apr 30, 2009 #2


    User Avatar
    Staff Emeritus
    Science Advisor
    Gold Member

    1's complement is simply an inversion of all the bits.

    2's complement acts as a "rotation" of the number circle, so that negative numbers can be represented, while addition and subtraction continue to work as expected. When you get into more complicated arithmetic (division, etc.) you'll generally be using more complicated floating-point formats.

    - Warren
  4. Apr 30, 2009 #3


    User Avatar
    Science Advisor

    One place where ones complement is used in in checksums for error detection in data transmission. It turns out to be better than twos complement for error detection. For more detail, see Additive Checksums at neutrino.com

    Cheers -- sylas
  5. Apr 30, 2009 #4
    However 1s compliment is vanishingly rare in practice. All programming language implementations I am aware of internally use 2s compliment for normal negative integers.
  6. Apr 30, 2009 #5


    User Avatar
    Science Advisor

    Quite so -- in progamming languages. More widely, however, there are practical applications that are almost certainly at work for you right now, in the underlying transport layers involved as data for this message goes from the physicsforums server to your browser.

    One complement is commonly used in practice for checksums. The implementation of this in a programming language has to manage the ones complement addition explicitly, because one complement addition is not a basic operation in programming languages.

    Cheers -- sylas
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook