10 = Log(1024) / Log(2)
померить давление внизу башни, померить наверху, сделать вывод
Public Function GetPow(ByVal num&)
For GetPow = 0 To 31
If num And (2 ^ GetPow) Then
Exit Function
End If
Next GetPow
GetPow = Empty
End Function
Public Function GetPow(ByVal num!)
Do
num! = num! / 2
If Int(num!) = num! Then
GetPow = GetPow + 1
Else
Exit Do
End If
Loop
End Function
Public Function GetPow(ByVal num as long)
dim p as long, i as long
if num=0 then GetPow=1: Exit Function
if num =1 then GetPow=2: ExitFunction
p=2
for i=2 to num
p=p*2
next
end function
for i=2 to num
mov eax,1
rol eax, степень
Public Function GetPow(ByVal num&) As Long
Dim xnum$
xnum$ = Hex$(num&)
Select Case Mid$(xnum$, 1, 1)
Case "1": GetPow = 0
Case "2": GetPow = 1
Case "4": GetPow = 2
Case "8": GetPow = 3
End Select
GetPow = GetPow + 4 * Len(xnum$) - 4
End Function
Public Function GetPow(ByVal num&)
Dim bin As String
Do While num& > 1
bin = bin & Trim$(num& Mod 2)
num& = num& \ 2
Loop
bin = bin & Trim$(num&)
GetPow = InStr(bin, "1") - 1
End Function
Public Function GetPow(ByVal num As Long) As Long
If num And &HFFFF0000 Then GetPow = GetPow Or 16
If num And &HFF00FF00 Then GetPow = GetPow Or 8
If num And &HF0F0F0F0 Then GetPow = GetPow Or 4
If num And &HCCCCCCCC Then GetPow = GetPow Or 2
If num And &HAAAAAAAA Then GetPow = GetPow Or 1
End Function
Public Function GetPow(ByVal num As Double) As Long
Static lut As Object
If lut Is Nothing Then
Set lut = CreateObject("ADODB.Recordset")
lut.Fields.Append "pow", vbInteger
lut.Fields.Append "num", vbDouble
lut.Open
Dim pow As Integer
For pow = 0 To 31: lut.AddNew Array("pow", "num"), Array(pow, 2 ^ pow): Next
End If
lut.Filter = "num=" & num
GetPow = lut!pow
End Function
Public Function GetPow(ByVal num As Long) As Long
GetPow = Array(-1, 0, 1, 26, 2, 23, 27, -1, 3, 16, _
24, 30, 28, 11, -1, 13, 4, 7, 17, -1, _
25, 22, -1, 15, 29, 10, 12, 6, -1, 21, _
14, 9, 5, 20, 8, 19, 18)(num Mod 37)
End Function
Public Function GetPow(ByVal num As Long) As Long
GetPow = (CBool(num And &HFFFF0000) And 16) Or _
(CBool(num And &HFF00FF00) And 8) Or _
(CBool(num And &HF0F0F0F0) And 4) Or _
(CBool(num And &HCCCCCCCC) And 2) Or _
(CBool(num And &HAAAAAAAA) And 1)
End Function
Function GetPow(ByVal num As Long) As Long
If num < 2 Then Exit Function
GetPow = 1+GetPow(num\2)
End Function
Function GetPow(ByVal num As Long) As Long
GetPow = 32 - Len(RTrim$(Replace$(Replace$(Dec2Bin(num), String$(32, "0"), String$(32, "-")), "0", " ")))
End Function
Function Dec2Bin(ByVal Value As Long) As String
Dim I As Long, res As String
If Value < 0& Then
Value = &HFFFFFFFF + Value + 1
res = res & "1"
Else
res = res & "0"
End If
For I = 30 To 0 Step -1
If Value And 2 ^ I Then
Value = Value - 2 ^ I
res = res & "1"
Else
res = res & "0"
End If
Next I
Dec2Bin = res
End Function
alibek писал(а):Хм... А рекурсия?
- Код: Выделить всё
Function GetPow(ByVal num As Long) As Long
If num < 2 Then Exit Function
GetPow = 1+GetPow(num\2)
End Function
2^31, увы, не принимает, беззнаковость скажется на компактности.
Function GetPow(ByVal num As Double) As Long
Const Sqr2 = 1.4142135623731
Dim root As Double
If num < 2 Then Exit Function
root = Sqr(num)
If CLng(root) * root <> num Then
root = CLng(root / Sqr2)
GetPow = 1
End If
GetPow = GetPow + GetPow(root) * 2
End Function
Public Function GetPow(byval num&) as long
Select Case num&
Case = 1
GetPow = 0
Case = 2
GetPow = 1
Case = 4
GetPow = 2
Case = 8
GetPow = 3
Case = 16
GetPow = 4
Case = 32
GetPow = 5
Case = 64
GetPow = 6
Case = 128
GetPow = 7
Case = 256
GetPow = 8
Case = 512
GetPow = 9
Case = 1024
GetPow = 10
Case = 2048
GetPow = 11
Case = 4096
GetPow = 12
Case = 8192
GetPow = 13
Case = 16384
GetPow = 14
Case = 32768
GetPow = 15
Case = 65536
GetPow = 16
Case = 131072
GetPow = 17
Case = 262144
GetPow = 18
Case = 524288
GetPow = 19
Case = 1048576
GetPow = 20
Case = 2097152
GetPow = 21
Case = 4194304
GetPow = 22
Case = 8388608
GetPow = 23
Case = 16777216
GetPow = 24
Case = 33554432
GetPow = 25
Case = 67108864
GetPow = 26
Case = 134217728
GetPow = 27
Case = 268435456
GetPow = 28
Case = 536870912
GetPow = 29
Case = 1073741824
GetPow = 30
Case = 2147483648
GetPow = 31
End Select
End Function
Public Function GetPow(ByVal num As Double) As Long
CopyMemory GetPow, ByVal VarPtr(num) + 6, 2
GetPow = (GetPow \ 16) - 1023
End Function
Option Base 1
Function GetPow(ByVal num As Double) As Long
bases = Array(0, 4, 7, 10, 14, 17, 20, 24, 27, 30)
a = Len(CStr(num))
b = Len(CStr(num / 2))
c = Len(CStr(num / 4))
d = Len(CStr(num / 8))
GetPow = bases(a) - (a = b) - (a = c) - (a = d)
End Function
Function GetPow2(ByVal num As Double) As Long
On Error GoTo exit_function
Dim b As Long
For i = 31 To 0 Step -1
b = CLng(num)
num = num * 2
Next i
exit_function:
GetPow2 = i
End Function
Function GetPow3(ByVal num As Double) As Long
Dim p As Integer
Randomize
While num <> 2 ^ p
p = CInt(Rnd * 32)
Wend
GetPow3 = p
End Function
Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (lpfn As Any, ByVal param) As Long
Function GetPow(ByVal num As Long) As Long
GetPow = CallWindowProc(471695703125.1215@, num)
End Function
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 23