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 次瀏覽

開啟你的 職業生涯

完成課程獲得認證

開始學習
廣告
© . All rights reserved.