Q:

What does ~0 mean in this code?

What's the meaning of ~0 in this code?
Can somebody analyze this code for me?
unsigned int Order(unsigned int maxPeriod = ~0) const
{
    Point r = *this;
    unsigned int n = 0;
    while( r.x_ != 0 && r.y_ != 0 )
    {
        ++n;
        r += *this;
        if ( n > maxPeriod ) break;
    }
    return n;
}

A:

~0 is the bitwise complement of 0, which is a number with all bits filled. For an unsigned 32-bit int, that's 0xffffffff. The exact number of fs will depend on the size of the value that you assign ~0 to.

A:

It's the one complement, which inverts all bits.
 ~  0101 => 1010
 ~  0000 => 1111
 ~  1111 => 0000

A:

As others have mentioned, the ~ operator performs bitwise complement. However, the result of performing the operation on a signed value is not defined by the standard.
In particular, the value of ~0 need not be -1, which is probably the value intended. Setting the default argument to
unsigned int maxPeriod = -1

would make maxPeriod contain the highest possible value (signed to unsigned conversion is defined as an assignment modulo 2**n, where n is a characteristic number of the given unsigned type (the number of bits of representation)).
Also note that default arguments are not valid in C.

