50% OFF!!!

Thursday, June 18, 2009

Bits and bitwise operation in C#


Here is an example for bits string format and bitwise opertaion (not).
It helps us to print the number as bit representation.

Example (using console application):
using System;
class MainClass
{
static void Main()
{
int[] values = { 0, 0x111, 0xfffff, 0x8888, 0x22000022};
foreach (int v in values)
{
Console.WriteLine("~0x{0:x8} = 0x{1:x8}", v, ~v);
}
}
}


Output:
~0x00000000 = 0xffffffff
~0x00000111 = 0xfffffeee
~0x000fffff = 0xfff00000
~0x00008888 = 0xffff7777
~0x22000022 = 0xddffffdd


Helpful for "bits users" which deal with common bit operations...


Source: http://msdn.microsoft.com/en-us/library/d2bd4x66(VS.80).aspx

No comments:

Post a Comment