Home »
VB.Net »
VB.Net Programs
VB.Net program to print the binary number of a decimal number
By Nidhi Last Updated : November 16, 2024
Printing the binary number of a decimal number
Here we will print the binary number of a decimal number using bitwise operators.
VB.Net code to print the binary number of a decimal number
The source code to print the binary number of a decimal number is given below. The given program is compiled and executed successfully.
'VB.Net program to print the binary number
'of a decimal number.
Module Module1
Sub Main()
Dim iLoop As SByte
Dim num As SByte
Console.Write("Enter Number: ")
num = Byte.Parse(Console.ReadLine())
For iLoop = 7 To 0 Step -1
If ((1 << iLoop) And num) Then
Console.Write("1")
Else
Console.Write("0")
End If
Next
Console.ReadLine()
End Sub
End Module
Output:
Enter Number: 8
00001000
Explanation:
In the above program, we created a module Module1 that contains a Main() method. And, we created two local variables iLoop and num. After that, we entered a number and then we checked each bit of a given number using bitwise AND and bitwise left-shift operator and print the "1" for a high bit and print "0" for a low bit on the console screen.
VB.Net Basic Programs »