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)
SecondX = ToBinary(SecondNum)
DecAnd = ToBinary(FirstNum And SecondNum)
'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) As String
ToBinary = Number Mod 2
Do While Number > 0
Number = Number \ 2
ToBinary = ToBinary & Abs(Number Mod 2 > 0)
Loop
ToBinary = StrReverse(ToBinary)
If Len(ToBinary) > 1 Then ToBinary = Mid(ToBinary, 2)
End Function
|