关于Visual Basic中二进制加法程序的评论

时间:2013-06-10 17:52:00

标签: vb.net binary console-application addition

我有一个二进制加法控制台应用程序的代码,它基本上加了两个二进制数。有人可以向我解释它是如何工作的,或者用代码写评论以显示每个部分的工作原理。

P.S所有我不明白的是功能

下面是代码:

    Dim a As Integer = 8
Dim b As Integer = 2
Dim c As Integer = 10
Sub Main()
    Dim binary1 As Integer
    Dim binary2 As Integer
    Console.WriteLine("---------------------BINARY ADDITION---------------------")
    Console.WriteLine("Enter in your two binary numbers")
    Console.WriteLine("1st number")
    binary1 = Console.ReadLine
    Console.WriteLine("2nd number")
    binary2 = Console.ReadLine
    Console.WriteLine(binary1 & "+" & binary2 & "=")
    binary1 = binary1 + binary2
    Console.Write(add(binary1))
    Console.ReadLine()



End Sub
Function add(ByVal x As Integer)
    For y As Integer = 1 To 8
        If x Mod c >= b Then
            x = x + a
        End If
        a = a * 10
        b = b * 10
        c = c * 10
    Next
    Return x
End Function

0 个答案:

没有答案