一、在全局脚本里面新建两个函数:
代码如下:
'''
'''16个Bit转Word
'''接收参数为包含16个元素的数组
'''其中每个元素依次对应16个Bit中的一个
Function bits2Word(Byval arr)
Dim res
res = 0
If Not IsArray(arr) Then
Msgbox "arr is not a array."
Elseif UBound(arr) <> 15 Then
Msgbox "the length of array must be 16."
Else
Dim x,y,idx
For idx = 0 To 15
x = arr(idx)
y = pow(2,(15 - idx))
res = res + (x * y)
Next
End If
bits2Word = res
End Function
'''辅助函数:求num的n次方
Function pow(Byval num,Byval n)
If n = 0 Then
pow = 1
Else
pow = pow(num , n - 1) * num
End If
End Function
二、在VBS脚本中调用:
代码调用实例如下:
Dim word
word = bits2Word(Array(1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1))
Msgbox word