Confusion with 1's and 2's complement

  • Thread starter Thread starter neo_star
  • Start date Start date
  • Tags Tags
    Confusion
Click For Summary

Discussion Overview

The discussion centers around the concepts of 1's and 2's complement, particularly their applications and the reasons for their existence. Participants explore the contexts in which each complement is used, their differences, and their relevance in programming and data transmission.

Discussion Character

  • Exploratory
  • Technical explanation
  • Debate/contested

Main Points Raised

  • One participant expresses confusion about the uses of 1's and 2's complement, questioning whether 1's complement is limited to specific operations and why both types exist.
  • Another participant explains that 1's complement involves inverting all bits, while 2's complement allows for negative number representation and maintains arithmetic consistency.
  • A participant notes that 1's complement is used in checksums for error detection, suggesting it is more effective than 2's complement in this context.
  • Some participants argue that 1's complement is rarely used in practice, with most programming languages employing 2's complement for negative integers.
  • One participant highlights that while 1's complement is uncommon in programming languages, it still finds practical applications in data transmission, particularly in checksums, which require explicit management of 1's complement addition.

Areas of Agreement / Disagreement

Participants generally agree that 2's complement is more prevalent in programming languages, while there is some contention regarding the practical applications of 1's complement, particularly in checksums and error detection.

Contextual Notes

The discussion reflects varying levels of familiarity with the technical details of 1's and 2's complement, and there are unresolved questions about the broader implications and applications of each type in different contexts.

neo_star
Messages
3
Reaction score
0
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.
 
Technology news on Phys.org
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
 
neo_star said:
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
 
However 1s compliment is vanishingly rare in practice. All programming language implementations I am aware of internally use 2s compliment for normal negative integers.
 
Coin said:
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
 

Similar threads

  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
1K
Replies
5
Views
2K
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
9K
Replies
1
Views
3K
Replies
3
Views
13K
Replies
6
Views
4K