ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to print the binary number of a decimal number

Here, we are going to learn how to print the binary number of a decimal number in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here we will print the binary number of a decimal number using bitwise operators.

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.