Mega Code Archive

 
Categories / C# Book / 01 Language Basics
 

0067 Bitwise operators in C#

C# supports the following bitwise operators: Operator Meaning ~ 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