Home >Backend Development >C#.Net Tutorial >Bitwise right shift operator in C#

Bitwise right shift operator in C#

王林
王林forward
2023-09-15 18:13:021265browse

C# 中的按位右移运算符

#Bitwise operators act on bits and perform bitwise operations. In the bitwise right shift operator, the value of the left operand is shifted to the right by the number of bits specified by the right operand.

In the code below, we have the value -

60 i.e. 0011 1100

shift right %minus;

c = a >> 2;

shift right twice and convert to 15 -

15 i.e. 0000 1111

Example

You can try running the following code to implement the bitwise right shift operator in C#-

using System;
using System.Collections.Generic;
using System.Text;
namespace Demo {
   class toBinary {
      static void Main(string[] args) {
         int a = 60;    /* 60 = 0011 1100 */
         int b = 0;
         c = a >> 2;    /* 15 = 0000 1111 */
         Console.WriteLine("Value of b is {0}", b);
         Console.ReadLine();
      }
   }
}

The above is the detailed content of Bitwise right shift operator in C#. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete