# Thread: Unary NOT on 32-bit integers

1. ## Unary NOT on 32-bit integers

How come performing the unary NOT (~) opertion on int x = 0 gives the value of -1 and not a saturated int value?

2. Because of two's complement representation.

(x) + (~x +1) must always equal 0.

0 + -1 + 1 = 0

3. Even with unsigned integers?

4. You're just flipping all the bits, so the result can never be saturated. In a one's complement system the result would be 0 (-0) (signed).

5. How were you expecting negative numbers to be represented in an int?

6. Yea it makes sense to me for signed integers, but for unsigned integers I am not clear why this is also the case. Guess I should brush up on two's complement.

7. OK I think I see that C does not allow unsigned integers of this magnitude, but the bit representation is still all ones, correct? That's all that really matters to me.

8. For unsigned number you should get INT_MAX.

9. Code:
```#include <stdio.h>

int main() {
unsigned int x = 0;
printf("%u\n", ~x);
}```

10. %u, very helpful, thanks.

Popular pages Recent additions