Confusion with 1's and 2's complement

  • Thread starter neo_star
  • Start date
  • Tags
    Confusion
In summary: Indeed, 1s complement is not a common representation in practice, though it is used for error detection in some cases. Additive checksums using 1s complement are faster than 2s complement additive checksums, but this is not always the case. For more information, see "Additive Checksums" on the neutrino website.
  • #1
neo_star
3
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
  • #2
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
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
 
  • #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.
 
  • #5
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
 

1. What is the difference between 1's complement and 2's complement?

The main difference between 1's complement and 2's complement is how they handle negative numbers. In 1's complement, negative numbers are represented by flipping all the bits of the positive number. In 2's complement, negative numbers are represented by taking the 1's complement and adding 1 to the result.

2. Why do we need both 1's complement and 2's complement?

Both 1's complement and 2's complement are used in digital systems for representing negative numbers. 1's complement is useful for performing subtraction and 2's complement is useful for performing addition and subtraction, making it more versatile in mathematical operations.

3. How do we convert a number from 1's complement to 2's complement?

To convert a number from 1's complement to 2's complement, we first take the 1's complement of the number and then add 1 to the result. This will give us the equivalent number in 2's complement.

4. Can 1's complement and 2's complement be used interchangeably?

No, 1's complement and 2's complement cannot be used interchangeably. They have different representations for negative numbers and using them interchangeably can result in incorrect calculations. It is important to use the correct complement for the specific operation being performed.

5. How do we handle overflow in 2's complement?

In 2's complement, overflow occurs when the result of an operation is too large to be represented by the given number of bits. To handle overflow, we can either increase the number of bits used to represent the number or use a different data type that can accommodate larger numbers.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
624
Replies
5
Views
1K
  • Programming and Computer Science
Replies
1
Views
1K
  • Programming and Computer Science
Replies
1
Views
5K
  • Programming and Computer Science
Replies
6
Views
2K
  • Programming and Computer Science
Replies
1
Views
953
  • Programming and Computer Science
Replies
32
Views
1K
  • Programming and Computer Science
Replies
2
Views
8K
  • Programming and Computer Science
Replies
1
Views
2K
  • Programming and Computer Science
Replies
4
Views
12K
Back
Top