Possible Duplicate:
What is the tilde (~) in a C# enumeration?
I found the following bit of code on a this MSDN page.
(((Width * Planes * BitCount + 31) & ~31) / 8) * abs(Height)
This does indeed compile in C# visual studio 2010. What exactly is the tilde "~" doing in front of the number 31? I've never seen this syntax in an expression before.
In informal writing, a tilde is sometimes used before a number to mean “about” or “approximately.” For example, a sentence that reads I think my dog weighs ~20 pounds means I think my dog weighs about/around 20 pounds. This usage is likely based on the math usage of the tilde symbol to mean an approximate equivalency.
Another approximation symbol is the double tilde ≈, meaning "approximately equal to". The tilde is also used to indicate congruence of shapes by placing it over an = symbol, thus ≅.
Last updated: September 8, 2017. In JavaScript, the tilde ~ Bitwise NOT operator is commonly used right before an indexOf() to do a boolean check (truthy/falsy) on a string. On its own, indexOf() returns the index number of a String object passed in.
It's called a tilde. Around the 12th century, Spanish scribes, in part to save paper, placed the tilde over a letter to indicate that it was doubled. As time passed, the mark was only used over the letter “n”; eventually, the ñ became an actual letter of the Spanish alphabet.
~
- bitwise NOT operator, basically invert bits
31 in binary format is 11111, so ~31 == 11111111111111111111111111100000, or 0xFFFFFFE0 hexadecimal.
That is the bitwise complement operator, also known as bitwise negation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With