Possible Duplicate:
Convert an integer to binary without using the built-in bin function
This function receives as a parameter a number in base 10 and should return a list representing the same value expressed in binary as a list of bits, where the first element in the list is the most significant (leftmost) bit.
convert_10_to_2(11)
should return [1, 0, 1, 1]
I cannot use the binary function or outside functions, so it has to be done in a more complicated way.
b = ''
while num > 0:
b = str(num % 2) + b
num >>= 1
return (b)
Okay I got my code finally up, okay I get '1011'
, but I need [1,0,1,1]
, I can't really use any functions such as bin(x)
or binary_list
. That has been what's taking this question so long.