Imports System
Class Program
Private Shared Function RoundToPreviousPowerOf2(ByVal n As Integer) As Integer
If n <= 0 Then
Return 0
End If
Return CInt(Math.Pow(2, Math.Floor(Math.Log(n, 2))))
End Function
Public Shared Sub Main()
Dim num As Integer = 21
Console.WriteLine($"Previous power of 2: {RoundToPreviousPowerOf2(num)}")
End Sub
End Class
' run:
'
' Previous power of 2: 16
'