Home >Backend Development >C#.Net Tutorial >How to use right shift operator in C#?
The value of the left operand is shifted to the right by the number of bits specified by the right operand in the right shift operator.
Let us look at an example of right shift operator in C# -
using System; namespace OperatorsAppl { class Program { static void Main(string[] args) { int a = 60; /* 60 = 0011 1100 */ int b = 0; b = a >> 2; /* 15 = 0000 1111 */ Console.WriteLine("Right Shift Operator - Value of b is {0}", b); Console.ReadLine(); } } }
Above, the value of a is 60, which is 0011 1100 in binary.
Set the right shift operator, as shown in the above example. This will shift the bits to the right twice -
a >> 2
Now the output will be 15 which is
15 = 0000 1111
The above is the detailed content of How to use right shift operator in C#?. For more information, please follow other related articles on the PHP Chinese website!