Reputation: 131
I came across some code today that reads
public class SomeClass
{
int DEFAULT_INT = 5;
public static int SomeMethod()
{
return ~FooBar(DEFAULT_INT);
}
public static int SomeMethod(int i)
{
return ~FooBar(i);
}
public static int FooBar(i)
{
......
}
}
I have not seen this before and as far as I know its a legal name ~FooBar Does anyone know if the "~" does anything special?
Sorry I adjusted the code from the original post. I miss read the FooBar method.
Upvotes: 3
Views: 164
Reputation: 29836
As said above, it's a bitwise operator that reverses each bit.
The FooBar
method returns an int. Behind the scenes it returns 32 bits that will look something like:
1110000001100..... // 32 chars.
Performing ~
on that int will return 0001111110011.....
Another example:
~(101) = 010
~(000) = 111
Upvotes: 2