Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,970 questions

51,912 answers

573 users

How to count the total bits of a number in VB.NET

1 Answer

0 votes
Imports System

Public Class Program
	Public Shared Function totalBits(ByVal num As Integer) As Integer
		Return Math.Floor(Math.Log(num, 2.0)) + 1
    End Function

    Public Shared Sub Main()
        Dim n As Integer = 12 ' 1100 
        Console.WriteLine(totalBits(n))
		
        n = 386 ' 1 1000 0010
        Console.WriteLine(totalBits(n))
		
		n = 2658 ' 1010 0110 0010
        Console.WriteLine(totalBits(n))
    End Sub
End Class




' run:
'
' 4
' 9
' 12
'

 



answered Dec 6, 2021 by avibootz

Related questions

1 answer 96 views
1 answer 134 views
1 answer 99 views
1 answer 186 views
2 answers 135 views
...