3

I'm calling an external function that returns a very large int as an interpretation of a binary number. A real example would be this:

output = 56904843415172010980318367264425014256050490817210830044164893489159338592392

I'm trying to convert this number into binary using JavaScript with a function I found around, but since JavaScript only supports 64-bit numbers is not working. Is there any workaround or libraries to this?

The decimal-to-binary function I'm using:

function dec2bin(dec) {
    return (dec >>> 0).toString(2);
}
Alexander van Oostenrijk
  • 4,644
  • 3
  • 23
  • 37
Hiperfly
  • 227
  • 1
  • 10
  • 1
    Does this help you? [Ref_one](https://stackoverflow.com/questions/39334494/converting-large-numbers-from-binary-to-decimal-and-back-in-javascript) – Dhana D. Aug 17 '21 at 12:14

1 Answers1

4

const input = '56904843415172010980318367264425014256050490817210830044164893489159338592392';
const binaryRepresentation = BigInt(input).toString(2);
console.log(binaryRepresentation);
Reda Benchraa
  • 239
  • 2
  • 3