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 20 45551
"sarathy" <sp*********@gm ail.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?
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".
In article <11************ **********@h48g 2000cwc.googleg roups.com>,
"sarathy" <sp*********@gm ail.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.
Roy Smith wrote:
In article <11************ **********@h48g 2000cwc.googleg roups.com>,
"sarathy" <sp*********@gm ail.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 8bit 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.
Bill Pursell schrieb:
Roy Smith wrote:
>>In article <11************ **********@h48g 2000cwc.googleg roups.com>, "sarathy" <sp*********@gm ail.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 8bit ones complement, zero is represented as either
0x00 or 0x80. 0xff is 127.
8bit 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 signmagnitude have the advantage
of symmetric value range and others. There have been enough
threads on this.
Cheers
Michael

EMail: Mine is an /at/ gmx /dot/ de address.
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************ **********@h48g 2000cwc.googleg roups.com>,
"sarathy" <sp*********@gm ail.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 8bit 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.
Michael Mair wrote:
Bill Pursell schrieb:
Roy Smith wrote:
>In article <11************ **********@h48g 2000cwc.googleg roups.com>,
"sarathy" <sp*********@gm ail.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 8bit ones complement, zero is represented as either
0x00 or 0x80. 0xff is 127.
8bit 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
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
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) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics 
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

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 integers?
What are the pitfalls of them?

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.
Thanks alot.

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 complement of '2'?
or
is 'c' (two's complement of c) computed on the fly and the resulting
value is added to b ( b + (c))?

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 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
 
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 VC++ and gcc.

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.

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
please tell me how to do it.how this answers comes.This is a global
edge question.
please also tell me how to find 8's complement(7436)
please alos tell me how to find 3's,4's,5's,6's,7's,8's complements.

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 never really about MISRA, but rather the one's complement
representation of integer constant 0 and now how to zero memory
portably, I am bringing the topic to this group. Try to ignore CBF's
errors in the 1's complement 1 and sign magnitude 1...

by: marktang 
last post by:
ONU (Optical Network Unit) is one of the key components for providing highspeed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...

by: Hystou 
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
 
by: Oralloy 
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bitfields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++12 std=c++20 Wnarrowing bit_field.cpp
Here is the code in...

by: jinu1996 
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...

by: tracyyun 
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, ZWave, WiFi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...

by: isladogs 
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...

by: conductexam 
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...

by: adsilva 
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
 
by: bsmnconsultancy 
last post by:
In today's digital era, a welldesigned website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
 