public static BigInteger LeftShift(BigInteger value, int shift)
{
// Shifting by zero bits does nothing.
if (shift == 0)
return value;
// Shifting left by a negative number of bits is the same as shifting right.
if (shift < 0)
return RightShift(value, -shift);
int wordShift = shift / 32;
int bitShift = shift - (wordShift * 32);
uint[] outputBits = new uint[value.wordCount + wordShift + 1];
int outputWordCount = outputBits.Length - 1;
uint carry = 0;
for (int i = 0; i < value.wordCount; i++)
{
uint word = value.bits[i];
outputBits[i + wordShift] = (word << bitShift) | carry;
carry = bitShift == 0 ? 0 : word >> (32 - bitShift);
}
if (carry != 0)
{
outputBits[outputWordCount] = carry;
outputWordCount++;
}
return new BigInteger(outputBits, outputWordCount, value.sign);
}