首页  >  文章  >  后端开发  >  C# 中的按位右移运算符

C# 中的按位右移运算符

王林
王林转载
2023-09-15 18:13:021195浏览

C# 中的按位右移运算符

位运算符作用于位并执行逐位运算。在按位右移运算符中,左操作数的值向右移动右操作数指定的位数。

在下面的代码中,我们有值 -

60 i.e. 0011 1100

右移 %minus;

c = a >> 2;

右移两次后转换为 15 -

15 i.e. 0000 1111

示例

您可以尝试运行以下代码来实现 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();
      }
   }
}

以上是C# 中的按位右移运算符的详细内容。更多信息请关注PHP中文网其他相关文章!

声明:
本文转载于:tutorialspoint.com。如有侵权,请联系admin@php.cn删除