ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to check EVEN/ODD using bitwise operators

Here, we are going to learn how to check EVEN/ODD using bitwise operators in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here, we will read an integer number and check input number is EVEN or ODD using bitwise operators.

Program/Source Code:

The source code to check EVEN/ODD using bitwise operators is given below. The given program is compiled and executed successfully.

'VB.Net program to check EVEN/ODD using bitwise operators.

Module Module1

    Sub Main()
        Dim num As Integer = 0
        
        Console.Write("Enter the number: ")
        num = Integer.Parse(Console.ReadLine())

        'Result of num&1 is 0000000d where d is your LSB.
        '   - LSB is 1 for odd number
        '   - LSB is 0 for even number
        If ( (num And 1) = 1) Then
            Console.WriteLine("Given number is ODD")
        Else
            Console.WriteLine("Given number is EVEN")
        End If

        Console.ReadLine()
    End Sub

End Module

Output:

Enter the number: 7
Given number is ODD

Explanation:

In the above program, we created a module Module1 that contains a function Main(). In the Main() function, we read the integer number and then find the given number is EVEN or ODD using bitwise operators.

'Result of num&1 is 0000000d where d is your LSB.
'   - LSB is 1 for odd number
'   - LSB is 0 for even number
If ( (num And 1) = 1) Then
    Console.WriteLine("Given number is ODD")
Else
    Console.WriteLine("Given number is EVEN")
End If

The above code is used to check the given number is EVEN or ODD and print the appropriate message 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.