Home >>VB.Net Programs >VB.Net Program to perform BITWISE AND operation

VB.Net Program to perform BITWISE AND operation

Write a Program to perform BITWISE AND operation in VB.Net

Here, between two integer variables, we will perform a BITWISE AND operation and print the result.

Program

Below is the source code for performing BITWISE AND operations. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim num1 As Integer = 3
        Dim num2 As Integer = 2
        Dim res As Integer = 0
        res = num1 And num2
        Console.WriteLine("Result : " + res)
        Console.ReadLine()
    End Sub
End Module

Output:
Result: 2

Explanation:

We generated a Module1 module in the above program that contains the function Main (). Three local variables num1, num2, and res, initialized with 3, 2, and 0 respectively, have been generated in the Main() function.

res = num1 And num2
Now evaluate the above expression.
res = num1 And num2
res = 3 And 2
The binary equivalent of 3 is 11.
The binary equivalent of 2 is 10.
Then
11
10
====
10
That is 2.

Finally, on the console screen, we printed the value res.


No Sidebar ads