问题
Is two's complement notation of a positive number is same as its binary representation?
回答1:
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
回答2:
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.
回答3:
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).
回答4:
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.
回答5:
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
回答6:
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.
回答7:
You can use this to check how numbers get represented in twos comp.
来源:https://stackoverflow.com/questions/794062/is-twos-complement-notation-of-a-positive-number-the-same-number