C# 中的按位运算符是什么?
按位运算符作用于位并执行逐位操作。
以下是按位运算符。
下面的示例展示了如何在C#中使用按位运算符。
示例
using System;
namespace Demo {
class Program {
static void Main(string[] args) {
int a = 60; /* 60 = 0011 1100 */
int b = 13; /* 13 = 0000 1101 */
int c = 0;
c = a & b; /* 12 = 0000 1100 */
Console.WriteLine("Value of c is {0}", c );
c = a | b; /* 61 = 0011 1101 */
Console.WriteLine("Value of c is {0}", c);
c = a ^ b; /* 49 = 0011 0001 */
Console.WriteLine("Value of c is {0}", c);
c = ~a; /*-61 = 1100 0011 */
Console.WriteLine("Value of c is {0}", c);
c = a << 2; /* 240 = 1111 0000 */
Console.WriteLine("Value of c is {0}", c);
c = a >> 2; /* 15 = 0000 1111 */
Console.WriteLine("Value of c is {0}", c);
Console.ReadLine();
}
}
}输出结果Value of c is 12 Value of c is 61 Value of c is 49 Value of c is -61 Value of c is 240 Value of c is 15
热门推荐
1 训练狗狗憋尿
2 狗狗追踪训练
3 狗狗训练要多少钱
5 深圳狗狗训练
6 训练狗狗唤回
7 狗狗叫怎么训练
8 狗狗训练班
10 狗狗社会化训练
11 狗狗叫回训练
12 广州狗狗训练学校
13 狗狗训练躺下
14 狗狗随行训练
15 训练狗狗巡回
16 狗狗要怎么训练
17 狗狗喂食训练
18 训练狗狗躺下