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();
      }
   }
}

更新于: 2020 年 6 月 19 日

644 次浏览

开启你的 职业生涯

完成课程获得认证

开始学习
广告