What is the best way to store 4 bits from a byte in VB.NET? Where best means:
- The most straightforward method of storage from a Byte type.
- The easiest to work with while performing bitwise operations.
- Straightforward conversion of the bits to other types.
Storing them in a BitArray via its constructor reverses the order of the bits. This means that attempting to get the value of the first bit will require looking for that value in the last entry in the BitArray.
Storing them in an Array of Booleans does no present a straightforward way of conversion from the byte, and impedes the conversion to other types.
You could always create your own custom class if you don’t like how
BitArrayworks:Then, to use:
(I don’t know VB.NET, but I think this is correct).