我正在尝试将十六进制字符串转换为BigInt。
我不能使用来自node.js的默认node.js,因为我使用的是React本机,所以它工作得很好。
我试过使用大整数,但是我得到了错误:
Invalid integer这里的基本示例:https://playcode.io/943259
显示的是本机BigInt如何成功地将十六进制字符串转换为BigInt。然后,您可以注释掉我从大整数导入BigInt的第二部分,它会抛出错误。
let hexString ='0x9c46e9ec68e9bd4fe1faaba294cba38a71aa177534cdd1b6c7dc0dbd0abd7a7';
console.log('HexString to BigInt', BigInt(hexString));
//uncomment to get the error
//import BigInt from 'big-integer'
//console.log('HexString to BigInt', BigInt(hexString));发布于 2022-08-18 09:02:54
包大整数无法从字符串中检测到基数,但可以指定它。
import BigInt from 'big-integer'
let hexString ='0x9c46e9ec68e9bd4fe1faaba294cba38a71aa177534cdd1b6c7dc0dbd0abd7a7';
console.log('HexString to BigInt', BigInt(hexString.substring(2), 16));https://stackoverflow.com/questions/73399948
复制相似问题