Answers for "excel vba is bit set long"

VBA
20

excel vba is bit set long

'Extremely fast VBA function to test if a specified bit is set 
'within a 32-bit Long integer.

'Bits are numbered from 0 to 31, so the first (least significant) bit
'is bit 0.

'Note: we do not inspect bit 31, the sign bit.


Function LongBitIsSet(theLong&, bit As Byte) As Boolean
    Static i&, b&()
    If (Not Not b) = 0 Then
        ReDim b(0 To 30)
        For i = 0 To 30
            b(i) = 2 ^ i
        Next
    End If
    If bit < 31 Then LongBitIsSet = theLong And b(bit)
End Function


'------------------------------------------------------------------
MsgBox LongBitIsSet(255, 7)             '<--displays: True
MsgBox LongBitIsSet(230, 0)             '<--displays: False
MsgBox LongBitIsSet(16384, 14)          '<--displays: True
MsgBox LongBitIsSet(-16383, 0)          '<--displays: True
MsgBox LongBitIsSet(&H7FFFFFFF, 0)      '<--displays: True
Posted by: Guest on February-05-2021
22

vba is bit set in integer

'Extremely fast VBA function to test if a specified bit is set 
'within a 16-bit Integer.

'Bits are numbered from 0 to 15, so the first (least significant) bit
'is bit 0.

'Note: we do not inspect bit 15, the sign bit.


Function IntegerBitIsSet(theInteger%, bit As Byte) As Boolean
    Static i&, b%()
    If (Not Not b) = 0 Then
        ReDim b(0 To 14)
        For i = 0 To 14
            b(i) = 2 ^ i
        Next
    End If
    If bit < 15 Then IntegerBitIsSet = theInteger And b(bit)
End Function

'------------------------------------------------------------------
MsgBox IntegerBitIsSet(255, 7)      '<--displays: True
MsgBox IntegerBitIsSet(230, 0)      '<--displays: False
MsgBox IntegerBitIsSet(16384, 14)   '<--displays: True
MsgBox IntegerBitIsSet(-16383, 0)   '<--displays: True
Posted by: Guest on February-05-2021
15

excel vba set bit in byte

'Extremely fast VBA function to test if a specified bit is set 
'within a Byte.

'Bits are numbered from 0 to 7, so the first (least significant) bit
'is bit 0.

Function ByteBitIsSet(theByte As Byte, bit As Byte) As Boolean
    Static i&, b() As Byte
    If (Not Not b) = 0 Then
        ReDim b(0 To 7)
        For i = 0 To 7
            b(i) = 2 ^ i
        Next
    End If
    If bit < 8 Then ByteBitIsSet = theByte And b(bit)
End Function

'------------------------------------------------------------------
MsgBox ByteBitIsSet(255, 7)      '<--displays: True
MsgBox ByteBitIsSet(230, 0)      '<--displays: False
Posted by: Guest on February-05-2021
31

vba bits to byte

'Extremely fast VBA function to convert a binary string to a Byte:

Function BitsToByte(bits$) As Byte
    Dim i&
    Static b() As Byte
    If LenB(bits) > 16 Then Exit Function
    If LenB(bits) = 16 Then
        b = bits
    Else
        b = String$(8 - Len(bits), "0") & bits
    End If
    For i = 0 To 14 Step 2
        BitsToByte = 2 * BitsToByte Or (b(i) Xor 48)
    Next
End Function


'Example:

MsgBox BitsToByte("00001100")		'<--displays: 12
MsgBox BitsToByte("10000001")		'<--displays: 129
'
'
'
Posted by: Guest on February-03-2021

Code answers related to "excel vba is bit set long"

Code answers related to "VBA"

Browse Popular Code Answers by Language