Home > Backend Development > C#.Net Tutorial > How to use right shift operator in C#?

How to use right shift operator in C#?

王林
Release: 2023-08-28 09:09:14
forward
1369 people have browsed it

如何在 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();
      }
   }
}
Copy after login

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
Copy after login

Now the output will be 15 which is

15 = 0000 1111
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template