Материал из .Net Framework эксперт
Bitwise Operators
using System;
class MainClass
{
static void Main(string[] args)
{
long MyBit = 0x1;
long MyBitResult = 0;
MyBitResult = MyBit & 0x1;
Console.WriteLine(MyBitResult);
MyBitResult = MyBit | 0x2;
Console.WriteLine(MyBitResult);
MyBitResult = MyBit ^ 0x4;
Console.WriteLine(MyBitResult);
}
}
1
3
5
Display the bits within a byte.
using System;
class Example {
public static void Main() {
int t;
byte val;
val = 123;
for(t=128; t > 0; t = t/2) {
if((val & t) != 0)
Console.Write("1 ");
if((val & t) == 0)
Console.Write("0 ");
}
}
}
0 1 1 1 1 0 1 1