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

Here, we are going to demonstrate the left-shift operator (<<) in VB.Net.
Submitted by Nidhi, on November 26, 2020 [Last updated : February 18, 2023]

Left-shift operator (<<) in VB.Net

Here, we will perform a left-shift operation on integer number using a bitwise left-shift operator.

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

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

'VB.Net program to demonstrate the left-shift operator.

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: 4
Result is: 32

Explanation:

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

Here, we entered the value 4 for integer variable num, now we will evaluate the below expression.

    res = num << 3
    res = 4 * (23)
    res = 4 * 8
    res = 32

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

VB.Net Basic Programs »






Comments and Discussions!

Load comments ↻






Copyright © 2024 www.includehelp.com. All rights reserved.