0
How can I print binary combinations?
The user input should specify the number of bits. Example: #if user enters 1, then output: 0 1 #if user enters 2, then output: 00 01 10 11 #if user enters 3, then output: 000 001 010 011 100 101 110 111 Further, every output instance should be included in list, dictionary or whatever and can be accessible. Also, If I access an instance, can I separate out each digit? 110 -->1, 1, 0
1 Odpowiedź
+ 1
There's a built in function to transferm binary to int and int to binary
and the int() function can do that also ,it takes two parameters the number and the base u want that number to be in and transfer it to intger in that base
and to separate the numbers just make a for loop
example
numbers=[`11`,`22`,`33`,`45`,`55`,]
#store them as a string and
#make an empty list
diget=[]
for n in numbers:
n [0].append (diget)
n [1].append(diget)
and if u want to make it more efficient u can add an if statement to check how many digets in the string