devxlogo

Power2 – A power of 2

Power2 – A power of 2

' Raise 2 to a power' the exponent must be in the range [0,31]Function Power2(ByVal exponent As Long) As Long    Static res(0 To 31) As Long    Dim i As Long        ' rule out errors    If exponent  31 Then Err.Raise 5        ' initialize the array at the first call    If res(0) = 0 Then        res(0) = 1        For i = 1 To 30            res(i) = res(i - 1) * 2        Next        ' this is a special case        res(31) = &H80000000    End If        ' return the result    Power2 = res(exponent)        End Function

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist