Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
401 views
in Technique[技术] by (71.8m points)

c++ - JavaScript big integer from string to base 2

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...