0

I have a two-digit number (42 for example) and i have to get a list of bits for every digit like this

[[0, 1, 0, 0], [0, 0, 1, 0]]

how to do that?

1
  • Welcome to SO: You are encouraged to provide code that you have tried so far to overcome any problems you have encountered. If you haven't yet written any code, perhaps you should google your problem domain. Here is one example site that describes how to tackle your problem. Commented Apr 9, 2017 at 20:29

1 Answer 1

2
def bin(s):
   return str(s) if s<=1 else bin(s>>1) + str(s&1)

it's function for one digit, if you have multiple digits, do it for x % 10 and then divide your number by 10 for every digit

Sign up to request clarification or add additional context in comments.

1 Comment

I can also do map(bin, list(str(number))) where bin is your function

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.