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();
}
}
}
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP