Unary operators like that just need to be interpreted from right to left. ~
is the bitwise "not" operator, and !
is the boolean inverse. Thus, those three:
- convert the return value to an integer
- invert the bits of the integer
- inspect the number for "truthiness" (zero or non-zero,
false
or true
)
- invert the boolean value
- invert it again
The ~
here is the trickiest. The "search" routine (I surmise) returns -1
when it doesn't find anything. The ~
operator turns -1
to 0
, so the ~
allows one to interpret the "search" return value as true
(non-zero) if the target is found, and false
(zero) if not.
The subsequent application of !
— twice — forces the result to be a true boolean value. It's applied twice so that the true
/false
sense is maintained. edit Note that the forced conversion to boolean is not at all necessary in this particular code; the normal semantics of the if
statement would work fine with just the result of the ~
operator.