Span<uint> stackallocedXd = stackalloc uint[1];
Span<uint> xd = stackallocedXd;
bool negx = GetPartsForBitManipulation(ref value, ref xd);
+ bool trackSignBit = false;
if (negx)
{
}
NumericsHelpers.DangerousMakeTwosComplement(xd); // Mutates xd
+ if (xd[^1] == 0)
+ {
+ trackSignBit = true;
+ }
}
- int zl = xd.Length - digitShift;
+ int zl = xd.Length - digitShift + (trackSignBit ? 1: 0);
uint[]? zdArray = null;
Span<uint> zd = stackalloc uint[0];
if (zl > 0)
if (negx)
{
NumericsHelpers.DangerousMakeTwosComplement(zd); // Mutates zd
+
+ if (trackSignBit)
+ {
+ zd[^1] = 1;
+ }
}
return new BigInteger(zd, zdArray, negx);
tempByteArray2 = new byte[] { (byte)32 };
VerifyRightShiftString(Print(tempByteArray2) + Print(tempByteArray1) + "b>>");
}
+
+ // RightShift Method - All One Uint Large BigIntegers - 32 bit Shift
+ for (int i = 0; i < s_samples; i++)
+ {
+ tempByteArray1 = GetRandomLengthAllOnesUIntByteArray(s_random);
+ tempByteArray2 = new byte[] { (byte)32 };
+ VerifyRightShiftString(Print(tempByteArray2) + Print(tempByteArray1) + "b>>");
+ }
+
// RightShift Method - Large BigIntegers - large - Shift
for (int i = 0; i < s_samples; i++)
{
return value;
}
+ private static byte[] GetRandomLengthAllOnesUIntByteArray(Random random)
+ {
+ int gap = random.Next(0, 128);
+ int byteLength = 4 + gap * 4 + 1;
+ byte[] array = new byte[byteLength];
+ array[0] = 1;
+ array[^1] = 0xFF;
+ return array;
+ }
+
private static string Print(byte[] bytes)
{
return MyBigIntImp.Print(bytes);