|
▼向井 さん:
質問の内容がイマイチ理解できませんでした。
いろいろサンプルを書いてみました。
'こういうことですか?
Sub test()
Dim i As Long
Dim A As Long
For i = 1 To 40
A = A And i
Debug.Print "i=" & i & " : " & "A=" & A
A = A Or i
If i = A Then
Debug.Print i & ":OK"
Else
Debug.Print i & ":NG"
End If
Debug.Print
Next
End Sub
Sub test1()
Dim i As Long
Dim buf As Long
For i = 0 To 40
buf = i Xor &HFF
MsgBox i & "の2進:" & func_10to2(i) & vbCr & _
buf & "の2進:" & func_10to2(buf)
Next
End Sub
Sub Test2()
Dim H As Long 'Highの意
Dim L As Long 'Lowの意
Dim i As Long
For i = 0 To 40
H = i And &HF0
L = i And &HF
MsgBox i & "のHigh:" & func_10to2(H) & vbCr & _
i & "のLow:" & func_10to2(L)
Next
End Sub
Private Function func_10to2(ByVal arg As Long) As String
Dim buf As String
Dim i As Long
i = 0
Do Until arg = 0
If arg And 2 ^ i Then
buf = "1" & buf
arg = arg - 2 ^ i
Else
buf = "0" & buf
End If
i = i + 1
Loop
If Len(buf) < 8 Then
buf = WorksheetFunction.Rept("0", 8 - i) & buf
End If
func_10to2 = buf
End Function
|
|