1
The best solution to generate binary digits is to use a list to store the digits and a looping to reduce the variable entradaUsuario
at 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.
Follow the algorithm below:
Link to the project on the Scratch website: Decimal for Binary
If you really need to get the digits in separate variables, just run the algorithm without the looping, repeating the code for the number of binary digits you need:
The logic is incorrect. Use a list for the output of each binary digit within one looping if. Add 0 or 1 to the list as the result of the rest of the variable division
entradaUsuario
by 2. In addition to this check, update ("change")entradaUsuario
forarredondar para baixo de "entradaUsuario" / 2
and in the condition of looping, placerepita até que "entradaUsuario" < 0 ou "entradaUsuario" = 0
– Gomiero