BigInteger中destructiveMulAdd方法疑问

_冬木 2017-09-05 12:56:50
其中第15行和第17行分别取低32位和高32位是什么意思?

private static void destructiveMulAdd(int[] x, int y, int z) {
// Perform the multiplication word by word
//将y与z转换为long类型
long ylong = y & LONG_MASK;
long zlong = z & LONG_MASK;
int len = x.length;

long product = 0;
long carry = 0;
//从低位到高位分别与y相乘,每次都加上之前的进位,和传统乘法一模一样.
for (int i = len-1; i >= 0; i--) {
//每次相乘时将x[i]转换为long,这样其32位数就可转变为其真正代表的数
product = ylong * (x[i] & LONG_MASK) + carry;
//x[i]取乘积的低32位.
x[i] = (int)product;
//高32位为进位数,留到下次循环相加
carry = product >>> 32;
}

// Perform the addition
//执行加z
//mag最低位转换为long后与z相加
long sum = (x[len-1] & LONG_MASK) + zlong;
//mag最低位保留相加结果的低32位.
x[len-1] = (int)sum;
//高32位当成进位数
carry = sum >>> 32;
//和传统加法一样进位数不断向高位加
for (int i = len-2; i >= 0; i--) {
sum = (x[i] & LONG_MASK) + carry;
x[i] = (int)sum;
carry = sum >>> 32;
}
}
...全文
134 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

62,628

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧