19

Is two's complement notation of a positive number is same as its binary representation?

yesraaj
  • 46,370
  • 69
  • 194
  • 251
  • yes first bit(sign bit) is also ignored – yesraaj Apr 27 '09 at 15:37
  • 1
    The same number as what? Generally, positive numbers are the same in two's complement, one's complement, or sign-magnitude, if that's what you're asking. – David Thornley Apr 27 '09 at 16:44
  • whether all the positive number and its two's complement is the same number like 0111(binary) = 7 = 0111(7 in two's complement). – yesraaj Apr 27 '09 at 17:14

7 Answers7

21

Some of the answers and comments are getting the relationship between a "two's complement notation" and the "two's complement of a number" confused. The question may need to be clarified a bit, but it is clearly asking about "two's complement notation."

Two's complement notation includes both positive and negative numbers. Binary numbers can mean lots of things, so in order to determine what any binary number is supposed to represent, one must first know what notation or encoding is being used. The binary number could be an unsigned integer, two's complement integer, an IEEE floating point number, a string of characters, or something else entirely.

So 7 in two's complement notation is 00000111, just as it is as an unsigned integer. And -7 in two's complement notation is 11111001.

So, yes, positive integers in two's complement notation are represented the same way they are with unsigned integers (assuming it is a valid integer for the number of bits being used).

Rob Pilkington
  • 724
  • 5
  • 6
12

I think that you are confusing something here. Positive integers are generally stored as simple binary numbers. 1 is 1, 10 is 2, 11 is 3, etc.. Negative integers are stored as the two's complement of their absolute value, i.e. of the corresponding positive integer. The two's complement of a positive number is, when using this notation, a negative number.

In order to flip the sign of a number, you always calculate the two's complement of that number: flip all bits, then add 1. This is independent of whether the original number is positive or negative.

Example: 3 in 8-bit signed binary notation is 00000011. To flip the sign, you first flip all bits (11111100), then add 1 (11111101). So, -3 is 11111101. To flip the sign again, you first flip all bits (00000010), then add 1 (00000011), and you can see that this is the same 3.

Svante
  • 50,694
  • 11
  • 78
  • 122
  • 2
    "Two's complement notation" and "the two's complement of a number" are two different things. The question is about two's complement notation. – Rob Pilkington Apr 27 '09 at 17:07
  • Two's complement notation uses the n-bit two's complement to flip the sign. For 8-bit numbers, the number is subtracted from 2^8 to produce its negative. – Svante Apr 27 '09 at 22:10
8

Is two's complement notation of a positive number the same number?

The good example is from wiki that the relationship to two's complement is realized by noting that 256 = 255 + 1, and (255 − x) is the ones' complement of x

0000 0111=7 two's complement is 1111 1001= -7

the way it works is the msb(most significant bit) receives a negative value so in the case above

-7 = 1001= -8 + 0+ 0+ 1

Edit- A positive number written in two's-complement notation is the same as the number written in unsigned notation (although the most significant bit must be zero). A negative number can be written in two's complement notation by inverting all of the bits of its absolute value, then adding one to the result. Two's-complement notation

The maximum number that can be represented with a k-bit two's-complement notation is 2^(k-1)−1

TStamper
  • 30,098
  • 10
  • 66
  • 73
  • The "two's complement of a number" and "two's complement notation" are different things. Positive numbers can be represented in two's complement notation. – Rob Pilkington Apr 27 '09 at 17:15
6

from what I learnt in my computer science class, two's complement, one's complement and signed magnitude are the same only in a positive integer value. This will differ with negative integer values, where for one's complement you will have to flip the bits and for two's complement keeping the flipped bits and adding a 1 bit to getting the the negative bit to it's absolute integer.

I'm still learning, first year computer science student, hope it helped.

Jeff Atwood
  • 63,320
  • 48
  • 150
  • 153
sabeur
  • 55
  • 1
  • 2
1

No the 2's complement of positive number is not the same number,they are not stored in their 2's complement form in memory. In case of positive numbers they are stored as it is in memory,only in case of negative numbers the representation is in 2's complement form Negative numbers are stored in 2's complement form because 2’s complement is good for subtraction. Example: 5 + -7 = -2 Here -7 is stored in 2’s complement form (1001). 0101 + 1001 = 1110 Note that we automatically get a negative answer

0

This is true. If we don't add 1 to the negative number representation, we would have the values 0 and -0, which is a bit of a waste.

Dmitry Brant
  • 7,612
  • 2
  • 29
  • 47
-1

You can use this to check how numbers get represented in twos comp.