O'Reilly logo

C# 5.0 Unleashed by Bart De Smet

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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).

Image

FIGURE 5.20 Integral bitwise operations.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required