ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

VB.Net program to demonstrate the bitwise operators

Here, we are going to demonstrate the bitwise operators in VB.Net.
Submitted by Nidhi, on November 26, 2020

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

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.