Bitwise operators in C#

C# supports the following bitwise operators:

OperatorMeaning
~Complement
&And
|Or
^Exclusive Or
<<Shift left
>>Shift right

The following code shows how to use the bitwise operators.

 
using System;

class Program
{
    static void Main(string[] args)
    {
        int i = 5; 
        int j = 6;
        Console.WriteLine(i & j);
        Console.WriteLine(i | j);
        Console.WriteLine(i ^ j);
        Console.WriteLine(i << 2);
        Console.WriteLine(i >> 2);

    }
}
  

The output:


4
7
3
20
1
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.