What is 2's Complement Number? [closed]
Asked Answered
I

3

0

What is 2's Complement Number?
Why do we take 1's Complement and add 1 to it? Why don't we subtract 1 after taking 1's Complement?
Why do computers use 2's Complement?

Indiscernible answered 24/5, 2013 at 5:56 Comment(7)
how is this related to c or c++?Pyroxene
Did you look for this on Wikipedia at all? Or try researching with Google?Sharondasharos
because separating using simple numbers and 1's complement need carrying mechanism that is insufficient to implement in hardware, using 2's complement you can subtract numbers just like adding methodRoofdeck
And you question is inappropriate for SO as what you intend to ask has answers all over the internet.You clearly didn't search.I am voting to close.Interclavicle
possible duplicate of What is “2's Complement”?Sharondasharos
Welcome to Stack Overflow. Please read the FAQ soon. The trouble with this question is (1) it is easily searchable via Google, (2) it has been asked and answered before, and (3) it doesn't look as if you put much effort into finding an answer before asking the question. All of these characteristics lead to a negative reaction from the denizens of Stack Overflow.Sharondasharos
This is the best link I found: wikipedia: Two's complements. More general: wikipedia: Method of complements.Wien
W
7

What is 2's Complement Number?

Complementary number system is used to represent negative numbers. So, 2's Complement number system is used to represent negative numbers.

UPDATE

Q:  What “2’s Complement System” says?

A: The negative equivalent of binary number is its 2’s complement. (1’s Complement + 1)

Note: 1 extra bit is required to represent the sign of a number. MSB (Most Significant Bit) is used as sign bit. If MSB is 0, then the number is positive. If MSB is 1, then the number is negative.

1’s Complement  Value   2’s Complement
    011         +3          011
    010         +2          010
    001         +1          001
    000         +0          000
    111         -0          000
    110         -1          111
    101         -2          110
    100         -3          101
                -4          100

How '100' (3 bits) is -4?

MSB is used as sign, if 1, its negative, if 0 it is positive.

-1 * 2^2 + 0*2^1 + 0*2^0 = -4 + 0 + 0 = -4

Similarly 101 (3 bits) is -3

-1 * 2^2 + 0*2^1 + 1*2^0 = -4 + 0 + 1 = -3

Observations:

•   In 1’s complement, using 3 bits, we represented 2^3 = 8 numbers i.e from -3 to +3.
•   In 1’s complement, -0 and +0 are having 2 representation. (+0 is ‘000’ and -0 is ‘111’).
    But mathematically +0 and -0 are same.
•   In 2’s complement, using 3 bits, we represented only 2^3 = 8 numbers i.e from -4 to +3.
•   In 2’s complement, -0 and +0 are having same representation.
•   Since +0 and -0 in 2’s complement is having same representation, 
    we are left out with one more combination which is ‘100’ = -4.

Why do we take 1's Complement and add 1 to it? Why don't we subtract 1 after taking 1's Complement?

Refer "Why Inversion and Adding One Works" topic in the below link. If I start explaining, this post will grow big. http://www.cs.cornell.edu/~tomf/notes/cps104/twoscomp.html

Why computer uses 2' Complement?

  • Cos' of less hardware. If the computer is using 2' Complement means, it does subtraction using addition circuit. So, less hardware!!!
  • As seen in the above example, +0 and -0 have same representation. (1's complement and sign magnitude representation have 2 different representation for +0 and -0).
  • (Not an important) You will be able to represent one extra number using 2's complement. (in the above example its -4 which is '100' in binary using 3 bits).
Wainwright answered 24/5, 2013 at 5:57 Comment(0)
C
0

From Wikipedia Two's Complement :

The two's-complement system has the advantage that the fundamental arithmetic operations of addition, subtraction, and multiplication are identical to those for unsigned binary numbers (as long as the inputs are represented in the same number of bits and any overflow beyond those bits is discarded from the result). This property makes the system both simpler to implement and capable of easily handling higher precision arithmetic. Also, zero has only a single representation, obviating the subtleties associated with negative zero, which exists in one's-complement systems.

Clavicembalo answered 24/5, 2013 at 5:57 Comment(0)
S
0

The reason why we use two's complement rather than one's complement is to make arithmetic as simple as possible.

Consider that in one's complement, 1111 1111 and 0000 0000 are the same number - by subtracting one, we have ended up with...the same number. This is too big of a pain to have to think about - so instead we use two's complement, where 1111 1111 is -1 - by subtracting one, we successfully subtract one. Hooray!

(A secondary advantage is that we can represent one more unique number in two's complement than in one's complement — in two's complement -128 to +127 instead of one's complement -127 to +127.)

Sextodecimo answered 24/5, 2013 at 5:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.