我正在尝试将一个开源库从 .Net 4.0 转换到 3.5,但无法轻松地转换以下长乘法代码:
/// <summary>
/// Calculate the most significant 64 bits of the 128-bit
product x * y, where x and y are 64-bit integers.
/// </summary>
/// <returns>Returns the most significant 64 bits of the product x * y.</returns>
public static long mul64hi(long x, long y)
{
#if !NET35
BigInteger product = BigInteger.Multiply(x, y);
product = product >> 64;
long l = (long)product;
return l;
#else
throw new NotSupportedException(); //TODO!
#endif
}
正如您所看到的,作者没有找到一个方法来做到这一点。BigInteger
在.NET 3.5中不存在。
我如何在.NET 3.5上计算64*64乘法的高64位?