473,836 Members | 2,130 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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
20 45551

"Joe Wright" <jo********@com cast.netskrev i meddelandet
news:x9******** *************** *******@comcast .com...
Dik T. Winter wrote:
>In article <11************ **********@m79g 2000cwm.googleg roups.com>
"=?iso-8859-1?q?Kirit_S=E6l ensminde?="
<ki*********** *****@gmail.com writes:
> 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
52597
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
14384
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?
33
7720
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.
7
2131
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))?
22
979
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
6
4693
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.
14
10522
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
7570
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.
6
3401
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...
0
9811
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed 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...
0
10822
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields 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...
0
10532
jinu1996
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...
0
10241
tracyyun
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, Z-Wave, Wi-Fi, 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...
0
9359
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6975
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();...
0
5642
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.