Wow that was a lot of work, you don't have to do all that.
def bin_convert(x, count=8):
return "".join(map(lambda y:str((x>>y)&1), range(count-1, -1, -1)))
here are the functions comprising this one from easy->important
str()
returns a string
range()
is a way to get a list from 1 number to another. Written like this range(count-1, -1, -1)
counts backwards.
"".join()
is a way to take an iterable and put the pieces together.
map()
is a way to take a function and apply it to an iterable.
lambda
is a way to write a function in 1 line. I was being lazy and could have written another def func_name(y)
and it would have worked just as well.
>>
is a way to shift bits. (which I believe understanding this one is the key component to understanding your problem)