
BitVector32 Structure and BitVector32.Section Structure
Part of my 2008 study notes for exam 70-536 (.NET Framework 2.0).
Overview
- Used to manipulate the bits of a 32-bit integer.
- Used to pack multiple small numbers into one when storage is an issue.
Examples
Bitwise Manipulation
BitVector32 c = new BitVector32(0);
int firstBit = BitVector32.CreateMask();
int secondBit = BitVector32.CreateMask(firstBit);
int thirdBit = BitVector32.CreateMask(secondBit);
c[firstBit] = true;
c[thirdBit] = true;
Console.WriteLine(c.Data); // 5
Console.WriteLine(c); // BitVector32{00000000000000000000000000000101}
Bit Packing
BitVector32.Section a = BitVector32.CreateSection(10); // Max number to store is 10
BitVector32.Section b = BitVector32.CreateSection(80, a); // Max number to store is 80
BitVector32.Section c = BitVector32.CreateSection(5, b); // Max number to store is 5
BitVector32 x = new BitVector32(0);
x[a] = 5;
x[b] = 79;
x[c] = 3;
Console.WriteLine(x[a]); // 5
Console.WriteLine(x[b]); // 79
Console.WriteLine(x[c]); // 3
Console.WriteLine(x.Data); // 7413
Console.WriteLine(x); // BitVector32{00000000000000000001110011110101}
You May Also Like

Exam 70-536 Study Notes
My study notes for Microsoft exam 70-536: .NET types, collections, generics, I/O, serialization and more, with C# examples.

Starting Exam 70-536 Study
After a burnout, I'm putting my own project on hold to study for Microsoft exam 70-536.

Design Patterns - Proxy Pattern
The Proxy Pattern, and the last article in the design patterns series, now that I've finished reading Head First Design Patterns.



