1
function converterBinario () {
numero = document.getElementById("Valor-decimal").value;
var vetor = [];
var i =numero;
var cont=0;
while(i>0){
var resto = Math.floor(numero % 2);
if (resto == 0 | 1 ){
vetor[i] = resto;
console.log(resto);
}
numero= Math.floor(numero/2);
console.log(numero);
i--;
}
document.getElementById("resultado").innerHTML =vetor;
console.log(vetor);
}
I want to remove the zeros from the array that appear before 1.
It could be clearer in your question, an example of how the array is and how it should be
– Costamilam
Want to take all zeros out of the array?
– Sam
Take out all before the first 1.The array is 0,0,0,1,0,1.I want to leave 101.
– Lucas Soares