Home >>VB.Net Programs >VB.Net program to perform BITWISE OR operation

VB.Net program to perform BITWISE OR operation

Write a VB.Net program to perform BITWISE OR operation

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

Program

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

Example


Module Module1

    Sub Main()
        Dim x As Integer = 5
        Dim y As Integer = 2
        Dim res As Integer = 0
        res = x Or y
        Console.WriteLine("Result: {0}", res)
        Console.ReadLine()
    End Sub
End Module

Output:
Result: 7

Explanation:

We generated a Module1 module in the above program that contains the function Main (). Three local variables x, y, and res, initialized with 5, 2, and 0 respectively, were generated in the Main() function.

res = x Or y

Now evaluate the above expression.

res = x Or y
res = 5 Or 2

The binary equivalent of 5 is 101.

The binary equivalent of 2 is 010.

Then

101
010
====
111
That is 7.

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


No Sidebar ads