Convert decimal to binary in Scratch
Pq is not displaying the result on the screen? I tried to convert decimal number to binary in Scratch, but it's not working. Can anyone see what the mistake is?
1 answers
The best solution to generate the binary digits is to use a list to store the digits and a looping to reduce the variable entradaUsuario
with each iteration.
With each iteration of looping, the algorithm extracts the binary digit through a split-by-2 rest operation and stores that digit in the list.
Then divide entradaUsuario
by 2 until it reaches zero.
Follows the algorithm below:
Link to the project on the Scratch website: Decimal to binary
In case you really need to get the digits into separate variables, just run the algorithm without the looping , repeating the code for the number of binary digits you need: