从字符串到基数2的JavaScript大整数

时间:2017-03-20 23:07:55

标签: javascript c++ biginteger base gmp

如何从a JavaScript字符串开始,假设它将被转换为基数为2的数字表示,得到它的长度?

var a = "27253612834651292817068063108051952822914696443427141008555142123316682144932254071632833688593262045689493008241655341783955326980297437493219806268065150183246111733458990008880411449482143090406377611761078341580375284217607011541826787677233082585754389591236816422975207551625801435043443350389601614965";

npm packages jsbn没有它,big-integer以科学记数法返回(2e + ...)

我需要模仿mpz_sizeinbase(a, 2)的C ++代码结果 - gmplib.org/manual/Miscellaneous-Integer-Functions.html

1 个答案:

答案 0 :(得分:0)

我发现库在npm“big-integer”

中完成了我需要的所有工作
  1. 将字符串解析为biginteger https://github.com/peterolson/BigInteger.js#bigintnumber-base
  2. 将biginteger解析为字符串,将其转换为其他基础https://github.com/peterolson/BigInteger.js#override-methods