Task

Create and display the sequence of binary digits for a given   non-negative integer.

   The decimal value      5   should produce an output of               101
   The decimal value     50   should produce an output of            110010
   The decimal value   9000   should produce an output of    10001100101000

The results can be achieved using built-in radix functions within the language   (if these are available),   or alternatively a user defined function can be used.

The output produced should consist just of the binary digits of each number followed by a   newline.

There should be no other whitespace, radix or sign markers in the produced output, and leading zeros should not appear in the results.




 
Print DecToBin$(5)
Print DecToBin$(50)
Print DecToBin$(9000)
 
Print BinToDec$(DecToBin$(5)) '  101
Print BinToDec$(DecToBin$(50)) '110010
Print BinToDec$(DecToBin$(9000)) ' 10001100101000
 
End
 
Function DecToBin$ (digit As Integer)
    DecToBin$ = "Error"
    If digit < 1 Then
        Print " Error number invalid for conversion to binary"
        DecToBin$ = "error of input"
        Exit Function
    Else
 
        Dim As Integer TempD
        Dim binaryD As String
        binaryD = ""
        TempD = digit
        Do
            binaryD = Right$(Str$(TempD Mod 2), 1) + binaryD
            TempD = TempD \ 2
        Loop Until TempD = 0
        DecToBin$ = binaryD
    End If
End Function
 
Function BinToDec$ (digitB As String)
    BinToDec$ = "Error"
    If Len(digitB) < 1 Then
        Print " Error number invalid for conversion to decimal"
        BinToDec$ = "error of input"
        Exit Function
    Else
        Dim As Integer TempD
        Dim binaryD As String
        binaryD = digitB
        TempD = 0
        Do
            TempD = TempD + ((2 ^ (Len(binaryD) - 1)) * Val(Left$(binaryD, 1)))
            binaryD = Right$(binaryD, Len(binaryD) - 1)
        Loop Until Len(binaryD) = 0
        BinToDec$ = LTrim$(Str$(TempD))
    End If
End Function
 
 
 