Skip to main content
edited body
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71

In C, there is a keyword unsigned (not available in java), which can be used for declaring unsigned int x;. In the unsigned integers, the weight of the MSB is positive (2^31) rather thenthan being negative. In that case the range of an unsigned int is 0 to 2^32 - 1, wherewhile an int has range -2^31 to 2^31 - 1.

In C, there is a keyword unsigned (not available in java), which can be used for declaring unsigned int x;. In the unsigned integers, the weight of the MSB is positive (2^31) rather then being negative. In that case the range of an unsigned int is 0 to 2^32 - 1, where an int has range -2^31 to 2^31 - 1.

In C, there is a keyword unsigned (not available in java), which can be used for declaring unsigned int x;. In the unsigned integers, the weight of the MSB is positive (2^31) rather than being negative. In that case the range of an unsigned int is 0 to 2^32 - 1, while an int has range -2^31 to 2^31 - 1.

edited body
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71

So, the two's complimentcomplement thing is not an exclusive scheme for representing negative integers, rather we can say that the binary representation of integers are always the same, we just negate the weight of the most significant bit. And that bit determines the sign of the integer.

From another point of view, if you consider the two's complimentcomplement of x as ~x + 1 (NOT x plus one), here's the explanation:

So you can see that the negative x can be represented by ~x + 1, which we call the two's complimentcomplement of x.

So, the two's compliment thing is not an exclusive scheme for representing negative integers, rather we can say that the binary representation of integers are always the same, we just negate the weight of the most significant bit. And that bit determines the sign of the integer.

From another point of view, if you consider the two's compliment of x as ~x + 1 (NOT x plus one), here's the explanation:

So you can see that the negative x can be represented by ~x + 1, which we call the two's compliment of x.

So, the two's complement thing is not an exclusive scheme for representing negative integers, rather we can say that the binary representation of integers are always the same, we just negate the weight of the most significant bit. And that bit determines the sign of the integer.

From another point of view, if you consider the two's complement of x as ~x + 1 (NOT x plus one), here's the explanation:

So you can see that the negative x can be represented by ~x + 1, which we call the two's complement of x.

edited body
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71

Note that the weight of the MSB is negative (the largest possible negative actually), so shenwhen this bit is on, the whole number (the weighted sum) becomes negative.

Note that the weight of the MSB is negative (the largest possible negative actually), so shen this bit is on, the whole number (the weighted sum) becomes negative.

Note that the weight of the MSB is negative (the largest possible negative actually), so when this bit is on, the whole number (the weighted sum) becomes negative.

added 861 characters in body
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71
Loading
added 819 characters in body
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71
Loading
added 819 characters in body
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71
Loading
Source Link
Sufian Latif
  • 13.4k
  • 3
  • 36
  • 71
Loading