private static void AddBits64(byte[] data, ulong value, int bitPos, int bitsCount)
{
unchecked
{
int currentBytePos = bitPos / 8;
int currentBitInBytePos = bitPos % 8;
int xLength = Math.Min(bitsCount, 8 - currentBitInBytePos);
if (xLength != 0)
{
byte x1 = (byte)(value << 64 - bitsCount >> 56 + currentBitInBytePos);
data[currentBytePos] |= x1;
currentBytePos += (currentBitInBytePos + xLength) / 8;
currentBitInBytePos = (currentBitInBytePos + xLength) % 8;
int x2Length = bitsCount - xLength;
if (x2Length > 8)
x2Length = 8;
while (x2Length > 0)
{
xLength += x2Length;
byte x2 = (byte)(value >> bitsCount - xLength << 8 - x2Length);
data[currentBytePos] |= x2;
currentBytePos += (currentBitInBytePos + x2Length) / 8;
currentBitInBytePos = (currentBitInBytePos + x2Length) % 8;
x2Length = bitsCount - xLength;
if (x2Length > 8)
x2Length = 8;
}
}
}
}