Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
6
Task/Bitwise-operations/VBA/bitwise-operations-1.vba
Normal file
6
Task/Bitwise-operations/VBA/bitwise-operations-1.vba
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
Debug.Print Hex(&HF0F0 And &HFF00) 'F000
|
||||
Debug.Print Hex(&HF0F0 Or &HFF00) 'FFF0
|
||||
Debug.Print Hex(&HF0F0 Xor &HFF00) 'FF0
|
||||
Debug.Print Hex(Not &HF0F0) 'F0F
|
||||
Debug.Print Hex(&HF0F0 Eqv &HFF00) 'F00F
|
||||
Debug.Print Hex(&HF0F0 Imp &HFF00) 'FF0F
|
||||
79
Task/Bitwise-operations/VBA/bitwise-operations-2.vba
Normal file
79
Task/Bitwise-operations/VBA/bitwise-operations-2.vba
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
Function MaskL(k As Integer) As Long
|
||||
If k < 1 Then
|
||||
MaskL = 0
|
||||
ElseIf k > 31 Then
|
||||
MaskL = -1
|
||||
Else
|
||||
MaskL = (-1) Xor (2 ^ (32 - k) - 1)
|
||||
End If
|
||||
End Function
|
||||
Function MaskR(k As Integer) As Long
|
||||
If k < 1 Then
|
||||
MaskR = 0
|
||||
ElseIf k > 31 Then
|
||||
MaskR = -1
|
||||
Else
|
||||
MaskR = 2 ^ k - 1
|
||||
End If
|
||||
End Function
|
||||
Function Bit(k As Integer) As Long
|
||||
If k < 0 Or k > 31 Then
|
||||
Bit = 0
|
||||
ElseIf k = 31 Then
|
||||
Bit = MaskL(1)
|
||||
Else
|
||||
Bit = 2 ^ k
|
||||
End If
|
||||
End Function
|
||||
Function ShiftL(n As Long, k As Integer) As Long
|
||||
If k = 0 Then
|
||||
ShiftL = n
|
||||
ElseIf k > 31 Then
|
||||
ShiftL = 0
|
||||
ElseIf k < 0 Then
|
||||
ShiftL = ShiftR(n, -k)
|
||||
Else
|
||||
ShiftL = (n And MaskR(31 - k)) * 2 ^ k
|
||||
If (n And Bit(31 - k)) <> 0 Then ShiftL = ShiftL Or MaskL(1)
|
||||
End If
|
||||
End Function
|
||||
Function ShiftR(n As Long, k As Integer) As Long
|
||||
If k = 0 Then
|
||||
ShiftR = n
|
||||
ElseIf k > 31 Then
|
||||
ShiftR = 0
|
||||
ElseIf k < 0 Then
|
||||
ShiftR = ShiftL(n, -k)
|
||||
Else
|
||||
ShiftR = (n And MaskR(31)) \ 2 ^ k
|
||||
If (n And MaskL(1)) <> 0 Then ShiftR = ShiftR Or Bit(31 - k)
|
||||
End If
|
||||
End Function
|
||||
Function RotateL(n As Long, k As Integer) As Long
|
||||
k = (32768 + k) Mod 32
|
||||
If k = 0 Then
|
||||
RotateL = n
|
||||
Else
|
||||
RotateL = ShiftL(n, k) Or ShiftR(n, 32 - k)
|
||||
End If
|
||||
End Function
|
||||
Function RotateR(n As Long, k As Integer) As Long
|
||||
k = (32768 + k) Mod 32
|
||||
If k = 0 Then
|
||||
RotateR = n
|
||||
Else
|
||||
RotateR = ShiftR(n, k) Or ShiftL(n, 32 - k)
|
||||
End If
|
||||
End Function
|
||||
Function ClearBit(n As Long, k As Integer) As Long
|
||||
ClearBit = n And Not Bit(k)
|
||||
End Function
|
||||
Function SetBit(n As Long, k As Integer) As Long
|
||||
SetBit = n Or Bit(k)
|
||||
End Function
|
||||
Function SwitchBit(n As Long, k As Integer) As Long
|
||||
SwitchBit = n Xor Bit(k)
|
||||
End Function
|
||||
Function TestBit(n As Long, k As Integer) As Boolean
|
||||
TestBit = (n And Bit(k)) <> 0
|
||||
End Function
|
||||
11
Task/Bitwise-operations/VBA/bitwise-operations-3.vba
Normal file
11
Task/Bitwise-operations/VBA/bitwise-operations-3.vba
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
Debug.Print Hex(MaskL(8)) 'FF000000
|
||||
Debug.Print Hex(MaskR(8)) 'FF
|
||||
Debug.Print Hex(Bit(7)) '80
|
||||
Debug.Print Hex(ShiftL(-1, 8)) 'FFFFFF00
|
||||
Debug.Print Hex(ShiftL(-1, -8)) 'FFFFFF
|
||||
Debug.Print Hex(ShiftR(-1, 8)) 'FFFFFF
|
||||
Debug.Print Hex(ShiftR(-1, -8)) 'FFFFFF00
|
||||
Debug.Print Hex(RotateL(65535, 8)) 'FFFF00
|
||||
Debug.Print Hex(RotateL(65535, -8)) 'FF0000FF
|
||||
Debug.Print Hex(RotateR(65535, 8)) 'FF0000FF
|
||||
Debug.Print Hex(RotateR(65535, -8)) 'FFFF00
|
||||
Loading…
Add table
Add a link
Reference in a new issue