jrliv
5/11/2017 - 12:30 AM

Example of bit shift operators in C#.

Example of bit shift operators in C#.

byte a = 10; 	// 0000 1010 = 10
byte b = 20; 	// 0001 0100 = 20

Console.WriteLine("a << 1 = " + (a << 1));	// 0001 0100 = 20
Console.WriteLine("a >> 2 = " + (a >> 2));	// 0000 0010 = 2
Console.WriteLine("b >> 1 = " + (b >> 1));	// 0001 0100 = 20
Console.WriteLine("b << 1 = " + (b << 1));	// 0010 1000 = 40