×

VB.Net Programs

VB.Net program to demonstrate the bitwise operators

By Nidhi Last Updated : November 11, 2024

Bitwise Operators in VB.Net

We will create a program to demonstrate various operations using the bitwise operators and print the result on the console screen.

VB.Net code to demonstrate the bitwise operators

The source code to demonstrate the bitwise operators is given below. The given program is compiled and executed successfully.

'VB.Net program to demonstrate the bitwise operators.

Module Module1

    Sub Main()
        Dim a As Integer = 10
        Dim b As Integer = 3
        
        Dim result As Integer = 0
        
        '1010 & 0011 = 0010 = 3
        result = a & b
        Console.WriteLine("a & b  : {0}", result)
        
        '1010 ^ 0011 = 1001
        result = a ^ b
        Console.WriteLine("a ^ b  : {0}", result)
        
        '1010<<2 = 101000 = 40
        result = a << 2
        Console.WriteLine("a << b : {0}", result)
        
        '1010>>2 = 0010 = 2
        result = a >> 2
        Console.WriteLine("a >> b : {0}", result)
        
        Console.ReadLine()
    
    End Sub

End Module

Output:

a & b  : 103
a ^ b  : 1000
a << b : 40
a >> b : 2

Explanation:

In the above program, we created a Module that contains the Main() method, here we created three local variables a, b, and result that are initialized with 10, 3, and 0 respectively.

    '1010 & 0011 = 0010 = 3
    result = a & b
    Console.WriteLine("a & b  : {0}", result)

    '1010 ^ 0011 = 1001
    result = a ^ b
    Console.WriteLine("a ^ b  : {0}", result)

    '1010<<2 = 101000 = 40
    result = a << 2
    Console.WriteLine("a << b : {0}", result)

    '1010>>2 = 0010 = 2
    result = a >> 2
    Console.WriteLine("a >> b : {0}", result)

Here, we performed "bitwise AND", "bitwise XOR", "bitwise left-shift", and "bitwise right-shift" operations and print the result on the console screen.

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





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