Tuesday, February 24, 2009

BitVector32 constructor examples

static void Main(string[] args)
{
    int[] testData = new int[] { 
        int.MinValue, int.MinValue + 1,
        -2, -1, 0, 1, 2, 
        int.MaxValue - 1, int.MaxValue };
    foreach (int test in testData)
    {
        Console.WriteLine(string.Format("{0} -> {1}", test, new BitVector32(test)));
    }

    Console.ReadLine();
}

Outputs:

-2147483648 -> BitVector32{10000000000000000000000000000000}
-2147483647 -> BitVector32{10000000000000000000000000000001}
-2 -> BitVector32{11111111111111111111111111111110}
-1 -> BitVector32{11111111111111111111111111111111}
0 -> BitVector32{00000000000000000000000000000000}
1 -> BitVector32{00000000000000000000000000000001}
2 -> BitVector32{00000000000000000000000000000010}
2147483646 -> BitVector32{01111111111111111111111111111110}
2147483647 -> BitVector32{01111111111111111111111111111111}

So while new BitVector32(-1) may seem a bit odd for a constructor the intention is to set all 32 bits on.