public void WriteFixedBitCount(UInt32 value, int numBits)
{
if (numBits <= 0 || numBits > 32)
throw new ArgumentException("Number of bits shall be at most 32 bits");
if (((UInt64)1 << (numBits)) <= value)
throw new ArgumentException("Value can be represented with the number of bits specified");
for ( int i = 0; i < numBits; ++i)
{
var bitValue = 1U << i;
Write((value & bitValue) == bitValue);
}
}