Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

153
Views
How to convert base 2 integer with leading zeros to a string javascript

I'm given an array of integers such as:

const vals=[
  00100,
  11110,
  00100101,
  ...
]

and I need to simply make each value iterable maintaining the position of the leading zeros. My first thought was to turn them into strings, but JavaScript wants to use base 10 and nothing that I have tried will change this. And when I try parsing it back to base 2, the leading zeros are all swapped around:

let testNum = 00100; // saves as 64
testNum = parseInt(testNum, 10); // using radix 2 returns NaN
testNum = testNum.toString(2); // 1000000

Any help would be greatly appreciated!

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!