Feedback

Zahlen als Binär darstellen

Sprache: VB

Rechnet einen Beliebigen Wert in einen Binärwert um.
Public Class Form1

    Dim start As Integer = 178
    Dim currentbase As Integer = 1
    Dim output As String = ""

    Sub Binary()
        CalcFirst()
        Do Until currentbase = 0
            If currentbase < start Or currentbase = start Then
                output &= 1
                start -= currentbase
            Else
                output &= 0
            End If
            currentbase = currentbase / 2
        Loop
        MsgBox(output)
    End Sub

    Sub CalcFirst()
        Do Until start > currentbase And Not start > CInt(currentbase * 2)
            currentbase = currentbase * 2
        Loop
    End Sub

End Class
Public Class Form1

    Dim start As Integer = 178
    Dim currentbase As Integer = 1
    Dim output As String = ""

    Sub Binary()
        CalcFirst()
        Do Until currentbase = 0
            If currentbase < start Or currentbase = start Then
                output &= 1
                start -= currentbase
            Else
                output &= 0
            End If
            currentbase = currentbase / 2
        Loop
        MsgBox(output)
    End Sub

    Sub CalcFirst()
        Do Until start > currentbase And Not start > CInt(currentbase * 2)
            currentbase = currentbase * 2
        Loop
    End Sub

End Class

1 Kommentar