问题
I've got code for a binary addition console application which basically adds up two added binary numbers. could someone either explain to me how it works or write comments with the code to show how each part works.
P.S All i don't understand is the function
Heres the code:
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
来源:https://stackoverflow.com/questions/17029897/comments-on-binary-addition-program-in-visual-basic