office vba integer code example
Example 1: excel vba long integer to bits
Function LongToBits$(ByVal n&)
Dim i&
LongToBits = "00000000000000000000000000000000"
If n And &H80000000 Then
Mid$(LongToBits, 1, 1) = "1"
n = n And Not &H80000000
End If
For i = 32 To 2 Step -1
If n And 1 Then Mid$(LongToBits, i, 1) = "1"
n = n \ 2
Next
End Function
MsgBox LongToBits(0)
MsgBox LongToBits(293781237)
MsgBox LongToBits(-1)
Example 2: excel vba last byte from INTEGER
LoByte = n And &HFF
HiByte = (n And &HFF00&) \ &H100