在javascript中,我对大整数进行计算,例如61597086133919310755754988533408296568。我使用BigInteger库对这类数字进行计算(https://github.com/peterolson/BigInteger.js)。从我的后端服务中,我以长度为16的字节数组的形式接收这些数字,并且我还必须将我的计算结果作为长度为16的字节数组发回。
你有什么建议如何正确地解决这个问题吗?
发布于 2017-08-23 04:37:48
您可以通过对字节使用8位的左位移位来减少字节数组,然后将值相加。
var bytesArray = [255, 255, 255, 255],
intValue = bytesArray.reduce((r, a) => r.shiftLeft(8).add(a), bigInt.zero);
console.log(intValue.toString());https://stackoverflow.com/questions/45826108
复制相似问题