【发布时间】:2011-03-12 10:02:46
【问题描述】:
我正在 int 中使用 BigInteger 重新实现一个函数。现在有步骤
h = n >>> log2n--
但是我在这里遇到了麻烦。原代码中 h、n、log2n 都是 int 类型,如果我将 h、n、log2n 设置为 BigInteger,上面代码的等价表达式是什么?如何在 BigInteger 中执行无符号右移 (>>>)?
编辑:
代码块是:
int log2n = 31 - Integer.numberOfLeadingZeros(n);
int h = 0, shift = 0, high = 1;
while (h != n)
{
shift += h;
h = n >>> log2n--;
int len = high;
high = (h & 1) == 1 ? h : h - 1;
len = (high - len) / 2;
if (len > 0)
{
p = p.multiply(product(len));
r = r.multiply(p);
}
}
【问题讨论】:
-
你知道Java没有运算符重载,对吧?
-
是的。我不是说运算符重载。是不是有什么迂回的方式或方法或算法可以找到无符号移位操作?
标签: java biginteger bit-shift