vba long integer variable to bits code example
Example 1: excel-vba long integer value 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 make long from two shorts
Public Function MakeLong&(ByVal LoWord%, ByVal HiWord%)
MakeLong = (HiWord * &H10000) Or (LoWord And &HFFFF&)
End Function