In this article we will learn about some of the frequently asked Visual Basic programming questions in technical like “xl vba is specific bit set in longlong integer” Code Answer’s. When creating scripts and web applications, error handling is an important part. If your code lacks error checking code, your program may look very unprofessional and you may be open to security risks. Error handling in VBA is simple. An error message with filename, line number and a message describing the error is sent to the browser. This tutorial contains some of the most common error checking methods in Visual Basic. Below are some solution about “xl vba is specific bit set in longlong integer” Code Answer’s.
excel vba long integer to bits
xxxxxxxxxx
1
Function LongToBits$(ByVal n&)
2
Dim i&
3
LongToBits = "00000000000000000000000000000000"
4
If n And &H80000000 Then
5
Mid$(LongToBits, 1, 1) = "1"
6
n = n And Not &H80000000
7
End If
8
For i = 32 To 2 Step -1
9
If n And 1 Then Mid$(LongToBits, i, 1) = "1"
10
n = n 2
11
Next
12
End Function
13
14
'------------------------------------------------------------------------------
15
16
MsgBox LongToBits(0) '<--displays: 00000000000000000000000000000000
17
MsgBox LongToBits(293781237) '<--displays: 00010001100000101011111011110101
18
MsgBox LongToBits(-1) '<--displays: 11111111111111111111111111111111
19
xl vba is specific bit set in longlong integer
xxxxxxxxxx
1
'Extremely fast VBA function to test if a specified bit is set
2
'within a 64-bit LongLong integer.
3
4
'Bits are numbered from 0 to 63, so the first (least significant) bit
5
'is bit 0.
6
7
'Note: we do not inspect bit 63, the sign bit.
8
'Note: the LongLong data type is only available in 64-bit VBA.
9
10
11
Function LongLongBitIsSet(theLongLong^, bit As Byte) As Boolean
12
Static i&, b^()
13
If (Not Not b) = 0 Then
14
ReDim b(0 To 62)
15
For i = 0 To 62
16
b(i) = 2 ^ i
17
Next
18
End If
19
If bit < 63 Then LongLongBitIsSet = theLongLong And b(bit)
20
End Function
21
22
23
'------------------------------------------------------------------
24
MsgBox LongBitIsSet(255, 7) '<--displays: True
25
MsgBox LongBitIsSet(230, 0) '<--displays: False
26
MsgBox LongBitIsSet(16384, 14) '<--displays: True
27
MsgBox LongBitIsSet(-16383, 0) '<--displays: True
28
MsgBox LongBitIsSet(&H7FFFFFFF, 0), 0) '<--displays: True
29
MsgBox LongLongBitIsSet(&H7FFFFFFFFFFFFFff^, 62) '<--displays: True
30
'
31
'
32
'
33
34
35
36
excel vba is bit set long
xxxxxxxxxx
1
'Extremely fast VBA function to test if a specified bit is set
2
'within a 32-bit Long integer.
3
4
'Bits are numbered from 0 to 31, so the first (least significant) bit
5
'is bit 0.
6
7
'Note: we do not inspect bit 31, the sign bit.
8
'Note: any number of bits can be specified in one call.
9
10
11
Function LongBitIsSet(theLong&, bit As Byte) As Boolean
12
Static i&, b&()
13
If (Not Not b) = 0 Then
14
ReDim b(0 To 30)
15
For i = 0 To 30
16
b(i) = 2 ^ i
17
Next
18
End If
19
If bit < 31 Then LongBitIsSet = theLong And b(bit)
20
End Function
21
22
23
'------------------------------------------------------------------
24
MsgBox LongBitIsSet(255, 7) '<--displays: True
25
MsgBox LongBitIsSet(230, 0) '<--displays: False
26
MsgBox LongBitIsSet(16384, 14) '<--displays: True
27
MsgBox LongBitIsSet(-16383, 0) '<--displays: True
28
MsgBox LongBitIsSet(&H7FFFFFFF, 0) '<--displays: True
29
30
31
32
33