首頁  >  文章  >  後端開發  >  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刪除