Confusion with 1's and 2's complement

  • Thread starter neo_star
  • Start date
  • #1
3
0

Main Question or Discussion Point

Hi
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.
 

Answers and Replies

  • #2
chroot
Staff Emeritus
Science Advisor
Gold Member
10,226
34
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
 
  • #3
sylas
Science Advisor
1,646
6
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.
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
 
  • #4
560
1
However 1s compliment is vanishingly rare in practice. All programming language implementations I am aware of internally use 2s compliment for normal negative integers.
 
  • #5
sylas
Science Advisor
1,646
6
However 1s compliment is vanishingly rare in practice. All programming language implementations I am aware of internally use 2s compliment for normal negative integers.
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
 

Related Threads for: Confusion with 1's and 2's complement

  • Last Post
Replies
10
Views
32K
  • Last Post
Replies
2
Views
17K
  • Last Post
Replies
3
Views
4K
  • Last Post
Replies
5
Views
948
  • Last Post
Replies
4
Views
2K
Replies
12
Views
914
Top