parseInt not converting decimal to binary?

Use toString() instead of parseInt:

11..toString(2)
var str = "11";
var bin = (+str).toString(2);
console.log(bin)

According JavaScript’s Documentation:

The following examples all return NaN:

parseInt("546", 2); // Digits are not valid for binary representations

Leave a Comment