0

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

Ultra
  • 57
  • 8
  • You cannot convert `a` to a JavaScript `number` type as this one is limited to doubles. Do you want to convert `a` into another representation or simply get the number of digits of `a` if it were in base 2? – le_m Mar 20 '17 at 23:36
  • @le_m good point, altering my question right now! – Ultra Mar 21 '17 at 08:40

1 Answers1

0

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
Ultra
  • 57
  • 8