private int ParseBitCountAndExpandStreamAsNeeded(int bitCount) { if (InternalStream.Count == 0) { InternalStream.Add(0x00); } int oldPos = InternalStream.Count - 1; int bytesToAdd = 0; if ((bitCount + (BitPos - 1)) > Constants.ByteSizeInBits) { int adjustedBitCount = bitCount - (Constants.ByteSizeInBits - (BitPos - 1)); bytesToAdd = adjustedBitCount / Constants.ByteSizeInBits; if (adjustedBitCount % Constants.ByteSizeInBits != 0) { bytesToAdd++; } } if (ForceAddByte) { bytesToAdd++; oldPos++; } for (int i = 0; i < bytesToAdd; i++) { InternalStream.Add(0x00); } ForceAddByte = false; return(oldPos); }