I am having trouble with some code where the function is meant to convert the decimal numbers to binary from an array. I am using parseInt to do the conversions but it only prints the first number and more often prints NaN. My goal is to print all the binary equivalent of the decimal numbers on a html page.
Here is my code:
function decimal_table ()
{
// real_array stores decimal numbers.
const real_array = [];
const binary_array = [];
for (let i = 0; i <= 50; i++)
{
real_array.push(i);
document.getElementById("numbers").innerHTML = real_array.join(" ");
}
for (let b = 0; b <= 50; b++)
{
let calc = parseInt(real_array[b], 2);
binary_array.push(calc);
document.getElementById("binaries").innerHTML = binary_array.join(" ");
}
}
I want the output to look like this:
0 0000
1 0001
2 0010
3 0011
4 0100
and so on.