VB.Net program to check Nth bit of an integer number is SET or not

Here, we are going to learn how to check Nth bit of an integer number is SET or not in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here, we will check the nth bit of an integer number is HIGH or LOW using bitwise operators.

Program/Source Code:

The source code to check the nth bit of an integer number is SET or not is given below. The given program is compiled and executed successfully.

'VB.Net program to check nth bit of an 
'integer number is SET or not.

Module Module1

    Sub Main()
        Dim num As Integer = 0
        Dim bit As Integer = 0

        Console.Write("Enter Number: ")
        num = Integer.Parse(Console.ReadLine())

        Console.Write("Enter Bit position between 0-31: ")
        bit = Integer.Parse(Console.ReadLine())

        If ((1 << bit) And num) Then
            Console.WriteLine("bit {0} is set", bit)
            Console.WriteLine("bit {0} is not set", bit)
        End If

    End Sub

End Module


Enter Number: 15
Enter Bit position between 0-31: 3
bit 3 is set


In the above program, we created a module Module1 that contains a function Main(). In the Main() function, we declared two integer variables num and bit that are initialized with 0. After that we read values for variables num and bit. Then we checked the given bit of the given number is SET or NOT, and print an appropriate message on the console screen.

VB.Net Basic Programs »



Comments and Discussions




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

© some rights reserved.