Public Function DecAnd(ByVal FirstNum As Long, SecondNum As Long) As String
Dim FirstX As String
Dim SecondX As String
Dim i As Long
Const StrAnd As String = " AND "
Const StrEnd As String = " = "
Const LenX As Long = 10 'Длинна строки
DecAnd = String(LenX, "0")
FirstX = ToBinary(FirstNum, LenX)
SecondX = ToBinary(SecondNum, LenX)
For i = 1 To LenX
If Mid$(FirstX, i, 1) = Mid$(SecondX, i, 1) Then Mid$(DecAnd, i, 1) = Mid$(FirstX, i, 1)
Next i
DecAnd = FirstX & StrAnd & SecondX & StrEnd & DecAnd
End Function
Public Function ToBinary(ByVal Number As Long, Optional Digits As Long = 24) As String
Dim Ret As String 'Created by Lucas
Dim i As Long
Const ZERO As String = "0"
Const ONE As String = "1"
Ret = String(Digits, ZERO)
If Number Then
For i = Digits To 0 Step -1
If Number Mod 2 Then
Mid$(Ret, i, 1) = ONE
End If
Number = Number \ 2
Next i
End If
ToBinary = Ret
End Function
|