473,383 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

1's complement and 2's complement

Hi all,
I have a few doubts in the 1's and 2's complement
representation. Generally negative numbers can be represented using
either 1's complement or 2's complement representation.

1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1

i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???

2's complement of 2 ( 0000 0010 ) is -2 ( 1111 1110 )
Adding we get , 0000 0010 + 1111 1110 = 0000 0000 ==[ OK]

Does this complement representation have anything to do with the C's ~
[1's complement] operator ?
Is this representation architecture dependent or compiler dependent ?

Please clarify,

Regards,
Sarathy

Aug 1 '06 #1
20 45474
"sarathy" <sp*********@gmail.comwrote:
# Hi all,
# I have a few doubts in the 1's and 2's complement
# representation. Generally negative numbers can be represented using
# either 1's complement or 2's complement representation.
#
# 1's complement ---reverse all the bits
# 2's complement ---reverse all the bits + 1
#
# i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
# But when a number and its complement are added the result must be a
# zero right ??
# But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]

On a ones complement machine, ~0 is 0, called a negative zero.
Some CPUs convert -0 to +0, some don't. -0 = +0, but also
sometimes -0 < +0.

# Does this complement representation have anything to do with the C's ~
# [1's complement] operator ?

On ones complement CPUs, -x = ~x. Whether this was signficant when C
was first created, you would have to ask Ritchie.

--
SM Ryan http://www.rawbw.com/~wyrmwif/
So....that would make Bethany part black?
Aug 1 '06 #2
sarathy wrote:
Hi all,
I have a few doubts in the 1's and 2's complement
representation. Generally negative numbers can be represented using
either 1's complement or 2's complement representation.

1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1

i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???
In a pure 1's complement notation, you have the concept of "minus zero",
which is the ones complement of 0.

So your result is "minus zero".
Aug 1 '06 #3
In article <11**********************@h48g2000cwc.googlegroups .com>,
"sarathy" <sp*********@gmail.comwrote:
Hi all,
I have a few doubts in the 1's and 2's complement
representation. Generally negative numbers can be represented using
either 1's complement or 2's complement representation.

1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1

i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???
You did. In 1's complement, there is no unique representation for zero.
All 0's and all 1's are both equal to zero.
Does this complement representation have anything to do with the C's ~
[1's complement] operator ?
Not really
Is this representation architecture dependent or compiler dependent ?
Whether you are doing 1's complement or 2's complement math depends on the
underlying hardware. That being said, I haven't seen a 1's complement
machine in a couple of eons. It's pretty much an obsolete concept as far
as hardware design goes.
Aug 1 '06 #4
Roy Smith wrote:
In article <11**********************@h48g2000cwc.googlegroups .com>,
"sarathy" <sp*********@gmail.comwrote:
1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1

i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???

You did. In 1's complement, there is no unique representation for zero.
All 0's and all 1's are both equal to zero.
No, in 8-bit ones complement, zero is represented as either
0x00 or 0x80. 0xff is -127.

The problem is that addition with one's complement is
not the same as addition with 2's complement. To
add two numbers, you have to perform different operations
depending on the signedness of the numbers, and that
is why 2's complement is preferred.

Aug 1 '06 #5
Bill Pursell schrieb:
Roy Smith wrote:
>>In article <11**********************@h48g2000cwc.googlegroups .com>,
"sarathy" <sp*********@gmail.comwrote:
>>>1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1

i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???

You did. In 1's complement, there is no unique representation for zero.
All 0's and all 1's are both equal to zero.

No, in 8-bit ones complement, zero is represented as either
0x00 or 0x80. 0xff is -127.
8-bit ones complement? You mean sign and magnitude.

There is only one kind of ones complement for C.

C99, 62.6.2#2: "
— the corresponding value with sign bit 0 is negated (sign and magnitude);
— the sign bit has the value -(2N) (two’s complement);
— the sign bit has the value -(2N - 1) (one’s complement).
"
The problem is that addition with one's complement is
not the same as addition with 2's complement. To
add two numbers, you have to perform different operations
depending on the signedness of the numbers, and that
is why 2's complement is preferred.
And one's complement and sign-magnitude have the advantage
of symmetric value range and others. There have been enough
threads on this.

Cheers
Michael
--
E-Mail: Mine is an /at/ gmx /dot/ de address.
Aug 1 '06 #6
Hi,
I guess -0 ==1111 1111 is correct in 1's complement notation.
-0 ==1000 0000 is in signed magnitude notation.

Please verify and revert back in case.

Rgrds,
Sarathy

Bill Pursell wrote:
Roy Smith wrote:
In article <11**********************@h48g2000cwc.googlegroups .com>,
"sarathy" <sp*********@gmail.comwrote:
1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1
>
i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???
You did. In 1's complement, there is no unique representation for zero.
All 0's and all 1's are both equal to zero.

No, in 8-bit ones complement, zero is represented as either
0x00 or 0x80. 0xff is -127.

The problem is that addition with one's complement is
not the same as addition with 2's complement. To
add two numbers, you have to perform different operations
depending on the signedness of the numbers, and that
is why 2's complement is preferred.
Aug 1 '06 #7

Michael Mair wrote:
Bill Pursell schrieb:
Roy Smith wrote:
>In article <11**********************@h48g2000cwc.googlegroups .com>,
"sarathy" <sp*********@gmail.comwrote:
>>1's complement ---reverse all the bits
2's complement ---reverse all the bits + 1

i.e 1's complement of 2 ( 0000 0010 ) is -2 ( 1111 1101 )
But when a number and its complement are added the result must be a
zero right ??
But in this case 0000 0010 + 1111 1101 = 1111 1111 ==[ ?? ]
Should'nt we be getting a zero as result ???

You did. In 1's complement, there is no unique representation for zero.
All 0's and all 1's are both equal to zero.
No, in 8-bit ones complement, zero is represented as either
0x00 or 0x80. 0xff is -127.

8-bit ones complement? You mean sign and magnitude.
Oops. Of course.
of symmetric value range and others. There have been enough
threads on this.
Agreed!!

--
Bill

Aug 1 '06 #8
sarathy posted:
Please verify and revert back in case.

*Cringe*

I'd love to bludgeon to death the next person I hear utter that phrase.

--

Frederick Gotham
Aug 1 '06 #9
Frederick Gotham said:
sarathy posted:
>Please verify and revert back in case.


*Cringe*

I'd love to bludgeon to death the next person I hear utter that phrase.
Are you sure about that? Please verify and revert back in case.

(And now if you'll excuse me, I have a plane to catch. Or a starship. Or
something... TAXI!)

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)
Aug 1 '06 #10

Roy Smith wrote:
That being said, I haven't seen a 1's complement
machine in a couple of eons. It's pretty much an obsolete concept as far
as hardware design goes.
Except of course as part of the format for IEEE floating point numbers
(float, double etc.).

http://www.arl.wustl.edu/~lockwood/c...ml#HEADING1-52
K

Aug 1 '06 #11

Roy Smith wrote:
It's pretty much an obsolete concept as far as hardware design goes.

Not quite, many DSP-oriented CPU's use 1's complement arithmetic.

The advantage is, in a chain calculation, the negates and carries can
be computed separately and andded back at the end. With two's
complement the "add one" has to be done on each negate.

Aug 1 '06 #12
"Kirit Sælensminde" <ki****************@gmail.comwrites:
Roy Smith wrote:
>That being said, I haven't seen a 1's complement
machine in a couple of eons. It's pretty much an obsolete concept as far
as hardware design goes.

Except of course as part of the format for IEEE floating point numbers
(float, double etc.).

http://www.arl.wustl.edu/~lockwood/c...ml#HEADING1-52
Actually, I think it's sign-and-magnitude, not one's-complement.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 1 '06 #13
In article <11**********************@m79g2000cwm.googlegroups .com"=?iso-8859-1?q?Kirit_S=E6lensminde?=" <ki****************@gmail.comwrites:
>
Roy Smith wrote:
That being said, I haven't seen a 1's complement
machine in a couple of eons. It's pretty much an obsolete concept as far
as hardware design goes.

Except of course as part of the format for IEEE floating point numbers
(float, double etc.).

http://www.arl.wustl.edu/~lockwood/c...ml#HEADING1-52
I would not trust a book by an author who does not know the difference
between 1-s complement and sign-magnitude. The last machine I had
access to that used 1-s complement was the CDC Cyber 750, and the
successor in 750 mode (both for int and for float).
--
dik t. winter, cwi, kruislaan 413, 1098 sj amsterdam, nederland, +31205924131
home: bovenover 215, 1025 jn amsterdam, nederland; http://www.cwi.nl/~dik/
Aug 1 '06 #14

Frederick Gotham wrote:
sarathy posted:
Please verify and revert back in case.


*Cringe*

I'd love to bludgeon to death the next person I hear utter that phrase.
I've never come across it before; what does it mean? Am I allowed to
revert to any previous condition, or is a particular one implied?

Aug 1 '06 #15
Dik T. Winter wrote:
In article <11**********************@m79g2000cwm.googlegroups .com"=?iso-8859-1?q?Kirit_S=E6lensminde?=" <ki****************@gmail.comwrites:
>
Roy Smith wrote:
That being said, I haven't seen a 1's complement
machine in a couple of eons. It's pretty much an obsolete concept as far
as hardware design goes.
>
Except of course as part of the format for IEEE floating point numbers
(float, double etc.).
>
http://www.arl.wustl.edu/~lockwood/c...ml#HEADING1-52

I would not trust a book by an author who does not know the difference
between 1-s complement and sign-magnitude. The last machine I had
access to that used 1-s complement was the CDC Cyber 750, and the
successor in 750 mode (both for int and for float).
Nobody doubts there were 1's complement iron, but when? The last CDC
machine I saw was the 160A in 1962 and I have no idea of its arithmetic
mode. In 1963 I learned the Philco 212/2000 system which was 2's
complement. Every machine I've seen since then is 2's complement for
integer arithmetic. That's 43 years. But I haven't seen them all.

What was the last 1's complement machine and when was it last produced?

I have never seen 'signed magnitude' integers on any machine.

Of course, IEEE floating point is signed magnitude. FP is not the issue.

--
Joe Wright
"Everything should be made as simple as possible, but not simpler."
--- Albert Einstein ---
Aug 2 '06 #16

Keith Thompson wrote:
Actually, I think it's sign-and-magnitude, not one's-complement.
Whoops. Fair enough.
K

Aug 2 '06 #17
In article <x9******************************@comcast.com>,
Joe Wright <jo********@comcast.netwrote:
What was the last 1's complement machine and when was it last produced?
Wikipedia (http://en.wikipedia.org/wiki/One%27s_complement) claims "the
PDP-1 and UNIVAC 1100/2200 series, among many others, used one's-complement
arithmetic."
Aug 2 '06 #18
"J. J. Farrell" <jj*@bcs.org.ukwrote:
Frederick Gotham wrote:
sarathy posted:
Please verify and revert back in case.
*Cringe*

I'd love to bludgeon to death the next person I hear utter that phrase.

I've never come across it before; what does it mean?
It's managementspeak. The presence of any meaning is purely optional.

Richard
Aug 2 '06 #19
rl*@hoekstra-uitgeverij.nl (Richard Bos) writes:
"J. J. Farrell" <jj*@bcs.org.ukwrote:
>Frederick Gotham wrote:
sarathy posted:
Please verify and revert back in case.

*Cringe*

I'd love to bludgeon to death the next person I hear utter that phrase.

I've never come across it before; what does it mean?

It's managementspeak. The presence of any meaning is purely optional.
Most managers would be smart enough to use the word "report" rather
than "revert".

Apart from that, sarathy did give the impression that he was ordering
us around. That probably wasn't his intent. The difference in
wording between a polite request and a politely-phrased order to an
underling can be subtle.

--
Keith Thompson (The_Other_Keith) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <* <http://users.sdsc.edu/~kst>
We must do something. This is something. Therefore, we must do this.
Aug 2 '06 #20

"Joe Wright" <jo********@comcast.netskrev i meddelandet
news:x9******************************@comcast.com. ..
Dik T. Winter wrote:
>In article <11**********************@m79g2000cwm.googlegroups .com>
"=?iso-8859-1?q?Kirit_S=E6lensminde?="
<ki****************@gmail.comwrites:
> Roy Smith wrote:
That being said, I haven't seen a 1's complement
machine in a couple of eons. It's pretty much an obsolete
concept as far
> as hardware design goes.
Except of course as part of the format for IEEE floating point
numbers
> (float, double etc.).
http://www.arl.wustl.edu/~lockwood/c...ml#HEADING1-52

I would not trust a book by an author who does not know the
difference
between 1-s complement and sign-magnitude. The last machine I had
access to that used 1-s complement was the CDC Cyber 750, and the
successor in 750 mode (both for int and for float).

Nobody doubts there were 1's complement iron, but when? The last CDC
machine I saw was the 160A in 1962 and I have no idea of its
arithmetic mode. In 1963 I learned the Philco 212/2000 system which
was 2's complement. Every machine I've seen since then is 2's
complement for integer arithmetic. That's 43 years. But I haven't
seen them all.

What was the last 1's complement machine and when was it last
produced?
The Unisys Clearpath 2200 - still very much in production!

http://www.unisys.com/products/mainf...ames/index.htm
This is one reason why C++ doesn't require 32 bit 2's complement
harware, when there are some that are 36 bit 1's complement.
Don't miss the webcast tomorrow, when the next model is launched! :-)

http://www.unisys.com/products/mainf...0727151029.htm

Bo Persson
Aug 2 '06 #21

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Abby | last post by:
I have an array which contain Hex no. in each position. For examples, unsigned char data; data = 0x00; data = 0x01; data = 0x02; data = 0xE; data = 0xEF; --> This is the checksum value
8
by: Mantorok Redgormor | last post by:
From least to greatest is it sign magnitude ones complement two's complement Where sign magnitude is the least way to represent integers and two's complement is the best way to represent...
33
by: Daniel Fadlun | last post by:
Is there a bigger, mathematical, data type in C than the double (64 bit) one or the old long double (80 bit)? I'd like to add precision to my mathematical application, but I can't figure out how....
7
by: Greenhorn | last post by:
Hi, Is two's complement always used as a storage method or is it computed while computing the expression involved. e.g., int a = -2, b = 3, c = 4, d; d = b - c; Here, is 'a' stored as two's...
22
by: sarathy | last post by:
Hi all, I have a few doubts in the 1's and 2's complement representation. Generally negative numbers can be represented using either 1's complement or 2's complement representation. 1's...
6
by: subramanian | last post by:
Suppose I have the following statement: unsigned char x = 0; If I do, printf("%u\", ~x); it prints the value of UINT_MAX. I am using Intel machine. This same result is printed in both...
14
by: darthghandi | last post by:
What would be the most efficient way to calculate the two's complement of a variable length byte array? Thanks for your time.
3
by: vijaybaskar3108 | last post by:
hi, I just want to know how to find complements for a number. These are the following answers for complements 2's complement(10110)=01010 4's complement(1230)=2110 5's complement(4322)=0123...
6
by: Dan Henry | last post by:
I need a sanity check. The following is an exchange on comp.arch.embedded with CBFalconer in a rather long MISRA related thread. Since my little section of that thread and area of interest was...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.