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);
}
1
  • 1
    Does this help you? Ref_one Commented Aug 17, 2021 at 12:14

1 Answer 1

6

const input = '56904843415172010980318367264425014256050490817210830044164893489159338592392';
const binaryRepresentation = BigInt(input).toString(2);
console.log(binaryRepresentation);

Sign up to request clarification or add additional context in comments.

2 Comments

Why so complicated? BigInt(input).toString(2) is all you need! (Assuming input is a string, as this answer also assumes.)
You are absolutely right (the answer was updated)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.