1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
Sub Test()
Dim nb_bits As Integer, i As Integer, max As Integer
Dim val_sel As String
Dim val_out As String
nb_bits = Application.InputBox("nombre de bits:", Type:=1)
If nb_bits < 0 Then Exit Sub
max = 2 ^ nb_bits
Range("a:b").NumberFormat = "@" 'pour afficher d
For i = 0 To max - 1
val_sel = Format(WorksheetFunction.Dec2Bin(i, nb_bits), String(nb_bits, "0"))
val_out = String(max - 1 - i, "0") & String(i, "1")
Cells(i + 2, 1).Value = val_sel 'cellule A(2+i)
Cells(i + 2, 2).Value = val_out ' cellule B(2+i)
Next i
End Sub |
Partager