Confusion with 1's and 2's complement

  • Thread starter Thread starter neo_star
  • Start date Start date
  • Tags Tags
    Confusion
Click For Summary
The discussion centers on the use of 1's and 2's complements in computing, particularly in relation to negative number representation and error detection. 2's complement is predominantly used in programming languages for representing negative integers due to its efficiency in arithmetic operations, allowing addition and subtraction to function seamlessly. In contrast, 1's complement is primarily utilized in checksums for error detection in data transmission, as it is more effective in this context. However, 1's complement is becoming increasingly rare in practical applications, with most programming environments favoring 2's complement for handling negative numbers. The conversation highlights the specific scenarios where each type of complement is applied and the reasons behind their usage.
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
 
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · 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
12K
Replies
6
Views
4K
  • · Replies 32 ·
2
Replies
32
Views
2K