Private
Function
ByteArrayToDecAtPos(
ByRef
byteArray()
As
Byte
,
ByVal
BytePos
As
Long
,
ByVal
BitPos
As
Integer
,
ByVal
CountBits)
As
Long
Dim
sizeOfByteArr
As
Long
sizeOfByteArr = (UBound(byteArray) - LBound(byteArray) + 1)
If
BytePos < 0
Or
BytePos > sizeOfByteArr
Or
CountBits > sizeOfByteArr * 8
Then
ByteArrayToDecAtPos = CVErr(xlErrValue)
Exit
Function
Else
ByteArrayToDecAtPos = 0
curByte = BytePos
For
i = 1
To
((CountBits - (BitPos - 1) + 7) / 8) - 1
temp = shr(byteArray(i - 1), (BitPos - 1))
If
i < ((CountBits - BitPos + 15) / 8)
And
(BitPos > 1)
Then
temp2 = shr(byteArray(i), (8 - (BitPos - 1)))
temp2 = shl(temp2, (BitPos - 1))
End
If
ByteArrayToDecAtPos = shl(ByteArrayToDecAtPos, 1) + temp
Next
i
temp = shr(byteArray(((CountBits - (BitPos - 1) + 7) / 8) - 1), (8 - ((CountBits + (BitPos - 1))
Mod
8))
Mod
8)
ByteArrayToDecAtPos = shl(ByteArrayToDecAtPos, ((CountBits + (BitPos - 1))
Mod
8)) + temp
End
If
End
Function