Comments on binary addition program in visual basic

会有一股神秘感。 提交于 2019-12-25 07:34:24

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!