DoReMi
DoReMi

Reputation: 221

Bit manipulation tilde

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?

Upvotes: 0

Views: 103

Answers (1)

rici
rici

Reputation: 241691

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

Upvotes: 1

Related Questions