Private Sub Form_Click()
Dim M As Long
Dim N As Long
Dim I As Long, K As Long
Dim sI As Long, eI As Long
N = -1
Do While N < 0
TempSTR = InputBox("请输入N(1的个数):", "南宫飘雪", "4")
If IsNumeric(TempSTR) Then
N = Val(TempSTR)
If N > 31 Then I = -1
End If
Loop
M = -1
Do While M < 0
TempSTR = InputBox("请输入N(1的个数):", "南宫飘雪", "4")
If IsNumeric(TempSTR) Then
M = Val(TempSTR)
If M + N > 31 Then M = -1
End If
Loop
If M = 0 Or N = 0 Then Exit Sub
Me.Cls
Me.AutoRedraw = True
Print Long2STR(2 ^ N - 1, M + N)
For I = 0 To N - 1
sI = 0: eI = 0
For K = 0 To I
sI = 2 * sI + 1
Next K
sI = sI * 2 ^ (N - I - 1)
For K = 1 To N - I - 1
eI = 2 * eI + 1
Next K
For K = 1 To M + N - K - I
Print Long2STR((sI * (2 ^ K)) Or eI, M + N)
Next
Next I
End Sub
Private Function Long2STR(ByVal NUM As Long, ByVal Lenght As Long) As String
Dim TempSTR As String
Do While NUM
TempSTR = CStr(NUM And 1) & TempSTR
NUM = NUM \ 2
Loop
Lenght = Lenght - Len(TempSTR)
If Lenght > 0 Then TempSTR = String(Lenght, "0") & TempSTR
Long2STR = TempSTR
End Function