卓越飞翔博客卓越飞翔博客

卓越飞翔 - 您值得收藏的技术分享站
技术文章20354本站已运行347

C# 中的按位右移运算符

<?xml encoding="utf-8" ?>

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#中定义自定义方法?
下一篇: 返回列表
留言与评论(共有 0 条评论)
   
验证码:
隐藏边栏