none
Decimal to binary wrong code RRS feed

  • Question

  • What is bad with my code?

    'definir arreglo de 5 casillas de valor 0 cada una
    cd = 3
    For i = 1 to cd
      bit[i]=0
    endfor

    'pedir numero
    textWindow.WriteLine("Introduzca un numero para convertirlo a binario")
    num = TextWindow.ReadNumber()

    'repetir 5 veces el siguiente paso
    For j=1 to cd
      'paso 4
      lol = Math.Power(2,(cd-1))
      If (num - lol) >= 0 Then
        bit[cd] = 1
        cd = cd - 1
        If cd = 0 then
          fin()
        EndIf
        
        num = num - lol
      EndIf
      
      If (num - lol) < 0 Then
        cd = cd - 1
      EndIf
      
    endfor
    fin()
    Sub fin
      For i = 0 to 4
        textwindow.Write(bit[5-i])
      EndFor
      TextWindow.Pause()
      Program.End()
    EndSub

    Tuesday, January 15, 2019 5:15 PM

Answers