Sub Main()
Dim N, x, byt, decnum As Integer
Dim binum As String = "", sdec As String
Dim p As Long
Console.Write("Enter decimal number: ")
sdec = Console.ReadLine()
If Integer.TryParse(sdec, decnum) = False Then
Console.WriteLine("Too big")
Exit Sub
End If
byt = 4
N = 8 * byt 'maximum of 4 bytes
p = 1 'place value
For x = 0 To N
If (decnum And p) = 0 Then
binum = "0" & binum 'concatenate the string
Else
binum = "1" & binum
End If
p = p + p 'double the place value
Next x
binum = binum.TrimStart("0"c) 'remove leading 0s to shorten display
Console.WriteLine() 'using manual conversion
Console.WriteLine(binum)
Console.WriteLine() 'using the Convert method:
Console.WriteLine(Convert.ToString(decnum, 2))
Console.ReadLine()
End Sub