Recently I started with all this programming, at this moment I am making a script that transforms a decimal number into binary without using the & or the String. The error that presents me is that giving it integer values brings me closer to the highest value, but using a floating value would not throw me the result. an example
If I use a while (a > = 2) when I enter the 24 It makes me all right until it reaches 3 because 3% 2 = 1 and up there well but when dividing 3/2 = 1.5 (1.5 approaches it to 2) and it generates an additional binary; but if I only use (a > 2) it works well with the number 24 but at the moment of entering another number like the 16 it would be missing a binary that should be done doing the operation of a% 2 when a == 2 ..
<script>
var listabinario = new Array();
alert("Bienvenido al programa");
a = parseInt(prompt("ingrese el numero decimal: "));
while (a > 2) {
numero = parseInt(a / 2);
b = parseInt(a % 2);
alert(a);
alert(b);
listabinario.push(b);
a = a - numero;
}
c = parseInt(a / 2);
listabinario.push(c);
alert(listabinario);
</script>