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

VB.Net program to demonstrate the left-shift operator (<<)

Demonstrate the left-shift operator (<<) in VB.Net

Here, using a bitwise left-shift operator, we can perform a left-shift operation on integer numbers.

Program

Below is the source code to demonstrate the left-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 << 5
        Console.Write("Result is: {0}", res)

        Console.ReadLine()
    End Sub
End Module

Output:
Enter Number: 6
Result is: 48

Explanation:

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

We entered a value of 6 for the integer variable num here, and now we will evaluate the expression below.

res = num << 5
    res = 6 * (23)
    res = 6 * 8
    res = 48

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


No Sidebar ads