Integral Bitwise Logical Operators
The available operators that deal with integral values—as usual defined for int
, uint
, long
, and ulong
—include the following:
& | ^ ~
These, respectively, correspond to the bitwise AND, OR, XOR (exclusive OR), and complement operations. The following are a few examples:
int x = 5;int y = 3;int and = x & y; // 1int or = x | y; // 7int xor = x ^ y; // 6int compX = ~x; // -6
Figure 5.20 illustrates the operation of those operators (restricting myself to 4-bit representations to save space).
Get C# 5.0 Unleashed now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.