首頁  >  文章  >  後端開發  >  如何在 C# 中使用右移運算子?

如何在 C# 中使用右移運算子?

王林
王林轉載
2023-08-28 09:09:141293瀏覽

如何在 C# 中使用右移运算符?

左運算元的值向右移動右移運算子中右邊運算元指定的位數。

讓我們看一下 C# 中右移運算子的範例 -

using System;

namespace OperatorsAppl {

   class Program {

      static void Main(string[] args) {
         int a = 60; /* 60 = 0011 1100 */
         int b = 0;

         b = a >> 2; /* 15 = 0000 1111 */
         Console.WriteLine("Right Shift Operator - Value of b is {0}", b);
         Console.ReadLine();
      }
   }
}

上面,a的值為60,即二進位的0011 1100。

設定右移運算符,如上例所示。這會將位元向右移動兩次 -

a >> 2

現在輸出將為 15,即

15 = 0000 1111

以上是如何在 C# 中使用右移運算子?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:tutorialspoint.com。如有侵權,請聯絡admin@php.cn刪除