Confusion with 1's and 2's complement

  • Thread starter Thread starter neo_star
  • Start date Start date
  • Tags Tags
    Confusion
AI Thread 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
 
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
Thread 'Project Documentation'
Trying to package up a small bank account manager project that I have been tempering on for a while. One that is certainly worth something to me. Although I have created methods to whip up quick documents with all fields and properties. I would like something better to reference in order to express the mechanical functions. It is unclear to me about any standardized format for code documentation that exists. I have tried object orientated diagrams with shapes to try and express the...
Back
Top