VB.Net program to count the total number of high bits in a given integer number

Here, we are going to learn how to count the total number of high bits in a given integer number in VB.Net?
Submitted by Nidhi, on November 26, 2020

Here, we will check the total high bits in a number and print the count to the console screen.

Program/Source Code:

The source code to count the total number of high bits in a given integer number is given below. The given program is compiled and executed successfully.

'VB.Net program to count the total high bits 
'in a given number.

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

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

        For iLoop = 0 To 31 Step 1
            If ((1 << iLoop) And num) Then
                countHighBits = countHighBits + 1
            End If

        Console.Write("Total high bits are:{0}", countHighBits)

    End Sub

End Module


Enter Number: 7
Total high bits are:3


In the above program, we created a module Module1 that contains a Main() method. Here, we created three local variables iLoop, num, and countHighBits. After that, we entered a number and then we checked each bit of a given number using bitwise AND and bitwise left-shift operators and count the total high bits in the given number and then print the count on the console screen.

VB.Net Basic Programs »



Comments and Discussions



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

© some rights reserved.