Csharp/CSharp Tutorial/Data Type/Bits — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 18:31, 26 мая 2010
Bitwise Operators
<source lang="csharp">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); }
}</source>
1 3 5
Display the bits within a byte.
<source lang="csharp">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 "); } }
}</source>
0 1 1 1 1 0 1 1