image
Physics Forums Logo
image
image
* Register * Upgrade Blogs Library Staff Rules Mark Forums Read
image
image   image
image

Go Back   Physics Forums > Other Sciences > Computing & Technology > Programming & Comp Sci


Reply

image Confusion with 1's and 2's complement Share It Thread Tools Search this Thread image
Old Apr30-09, 08:35 PM                  #1
neo_star

neo_star is Offline:
Posts: 3
Confusion with 1's and 2's complement

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.
  Reply With Quote
Old Apr30-09, 08:55 PM                  #2
chroot

PF Admin
 
chroot's Avatar

chroot is Offline:
Posts: 10,248
Re: Confusion with 1's and 2's complement

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
  Reply With Quote
Old Apr30-09, 09:43 PM                  #3
sylas
 
sylas's Avatar

sylas is Offline:
Posts: 1,010
Blog Entries: 3
Recognitions:
PF Contributor PF Contributor
Re: Confusion with 1's and 2's complement

Originally Posted by neo_star View Post
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
  Reply With Quote
Old Apr30-09, 10:18 PM                  #4
Coin

Coin is Offline:
Posts: 451
Re: Confusion with 1's and 2's complement

However 1s compliment is vanishingly rare in practice. All programming language implementations I am aware of internally use 2s compliment for normal negative integers.
  Reply With Quote
Old Apr30-09, 11:15 PM                  #5
sylas
 
sylas's Avatar

sylas is Offline:
Posts: 1,010
Blog Entries: 3
Recognitions:
PF Contributor PF Contributor
Re: Confusion with 1's and 2's complement

Originally Posted by Coin View Post
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
  Reply With Quote
image image
Reply

Tags
1's & 2's complement
Thread Tools


Similar Threads for: Confusion with 1's and 2's complement
Thread Thread Starter Forum Replies Last Post
9's complement snoggerT Engineering, Comp Sci, & Technology 2 Feb15-09 09:24 PM
2's complement fsm Engineering, Comp Sci, & Technology 2 Oct14-07 09:23 PM
rs complement ehrenfest Engineering, Comp Sci, & Technology 1 Sep15-07 09:10 AM
Sign magnitude/1's Complement/2's Complement HELP! JWest Engineering, Comp Sci, & Technology 0 Apr6-07 06:56 PM
2's complement in VB ionlylooklazy Programming & Comp Sci 2 Jan19-07 02:26 PM

Powered by vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd. © 2009 Physics Forums
Sciam | physorgPhysorg.com Science News Partner
image
image   image