C# 中的按位右移运算符
csharpserver side programmingprogramming更新于 2024/9/25 0:12:00
按位运算符对位进行操作,并逐位执行操作。在按位右移运算符中,左操作数的值按右操作数指定的位数向右移动。
在下面的代码中,我们有值 −
60 即 0011 1100
右移 %minus;
c = a >> 2;
右移两次 − 后转换为 15
15 即 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(); } } }