Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does ~0 mean in this code?

Tags:

c++

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;
}
like image 630
Amir Avatar asked Jun 08 '10 17:06

Amir


People also ask

What does 0 mean in code?

'\0' is referred to as NULL character or NULL terminator It is the character equivalent of integer 0(zero) as it refers to nothing In C language it is generally used to mark an end of a string.

What does %2 == 0 mean in Python?

0 votes. number % 2 == 0 is a valid boolean expression that checks whether number % 2 is equivalent to 0 . For even number s, the result is the value, True .

Why is code 0 and 1?

Binary is a base-2 number system invented by Gottfried Leibniz that's made up of only two numbers or digits: 0 (zero) and 1 (one). This numbering system is the basis for all binary code, which is used to write digital data such as the computer processor instructions used every day.

What is the meaning of == 0?

== 0 means "equal to 0 (zero)".


2 Answers

~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.

like image 188
JSBձոգչ Avatar answered Oct 12 '22 00:10

JSBձոգչ


It's the one complement, which inverts all bits.

 ~  0101 => 1010
 ~  0000 => 1111
 ~  1111 => 0000
like image 25
stacker Avatar answered Oct 11 '22 23:10

stacker