C #'~ 'Use of bitwise anti-Operators,
Bitwise inversion operator is the inverse of each bitwise of binary, such as byte type ,~ The result of 0 is 255.
This feature allows you to perform some reverse operations in the mask.
The following code stores values of 2, 4, and 8 in. Use bitwise inversion '~ 'Operator Inversion
The print result is false, flase, false, true, or true. The Mask has been reversed.
Class Program {static void Main (string [] args) {byte a = 2 | 4 | 8; byte B = (byte )~ A; Console. writeLine (B & 2) = 2); Console. writeLine (B & 4) = 4); Console. writeLine (B & 8) = 8); Console. writeLine (B & 16) = 16); Console. writeLine (B & 32) = 32); Console. read ();}}
For example, in the unity engine, this operation can be used on LayerMask:
Public class LayerMaskTest: MonoBehaviour {public LayerMask layerMask; void OnEnable () {layerMask. value = ~ LayerMask. value ;}}