0

I understand that tilde flips every bits, but if I do int num = ~0
Why the result is num = -1 , neither max value of int or unsigned int?

1

1 Answer 1

1

But it is the max value of unsigned:

#include <iostream>
#include <limits>

int main() {
  std::cout << ( unsigned(-1) == std::numeric_limits<unsigned>::max() )
            << std::endl;
  return 0;
}

http://ideone.com/y4JuFe

2
  • But if I do int unsigned int num = ~0, the result is num = 4294967295, I think this shall be the max of unsigned int
    – DoReMi
    Oct 7, 2013 at 0:19
  • 1
    Unsigned 4294967295 and signed -1 have the same bit pattern. Oct 7, 2013 at 0:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.