Home >>VB.Net Programs >VB.Net program to demonstrate the right-shift operator (>>)

VB.Net program to demonstrate the right-shift operator (>>)

Demonstrate the right-shift operator (>>) in VB.Net

Here, using a bitwise right-shift operator (>>), we can perform a right-shift operation on integer numbers.

Program

Below is the source code to demonstrate the right-shift operator (<<). The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim num As Integer = 0
        Dim res As Integer = 0

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

        res = num << 3
        Console.Write("Result is: {0}", res)

        Console.ReadLine()
    End Sub
End Module

Output:
Enter Number: 64
Result is:8

Explanation:

We generated a Module1 module in the program above that contains the Main() method. And we have developed two local variables, num and res, initialized with 0.

For the integer variable num, we entered the value 64, and now we will evaluate the expression below.

res = num >> 3
res = 64 / (23)
res = 64 / 8
res = 8

After that, on the console screen, we printed the value of variable res.


No Sidebar ads