JavaScript big integer from string to base 2

被刻印的时光 ゝ 提交于 2019-12-12 02:35:31

问题


How to from a JavaScript String, assuming that it will be converted to base 2 number representation, get length of it?

var a = "27253612834651292817068063108051952822914696443427141008555142123316682144932254071632833688593262045689493008241655341783955326980297437493219806268065150183246111733458990008880411449482143090406377611761078341580375284217607011541826787677233082585754389591236816422975207551625801435043443350389601614965";

npm packages jsbn dont have it and big-integer returns in science notation (2e+...)

I need to mimick C++ code result of mpz_sizeinbase(a, 2) - gmplib.org/manual/Miscellaneous-Integer-Functions.html


回答1:


I've found library that does all I need in npm "big-integer"

  1. Parse string to biginteger https://github.com/peterolson/BigInteger.js#bigintnumber-base
  2. Parse biginteger to string converting it to other base https://github.com/peterolson/BigInteger.js#override-methods


来源:https://stackoverflow.com/questions/42915607/javascript-big-integer-from-string-to-base-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!