title: Creating a decode algorithm
body: <p>How can I create an algorithm to decode a number (code) and associate it with a specific genre?</p>
  
  <p>For example: </p>
  
  <pre><code>0= 1 =zombie
  
  1= 2 =horror
  
  2= 4 =romance
  
  3= 8 =action
  
  4= 16 =medieval
  </code></pre>
  
  <p>This is my genres list. The reason it is set up like this is, say the user enters 3 then what would come out is zombie, horror because 1+2=3.</p>
  
  <p>How do I create a function that will take a code (int value) and return a list of genres that associate with it. If the code is (12) I need the function to return the list L=[4,8]. </p>
  
  <p>What I have figured out so far! I know that if the user enters 12 then 12 is less than 16 (the next power of 2) and is the previous 2 genres added together. I just don't know how to translate that into my code.</p>
  
  <pre><code>def _decode(self, code):
    codes=[] #need and empty list to add the values to
    #need code that will take the code value and associate it to its respective genres. 
    return codes
  </code></pre>
  
  <p>What i have done so far is this:</p>
  
  <pre><code>Def _decode(self, code):
  
  codes=[]
  
  for i in range (0,10):
  
   i = 2**i
  
   if i==code:
  
  codes.append(i)
  </code></pre>
  
  <p>What this is doing is, if the user enters 2 and 2 is already a power of 2 and can only be associated with 1 genera it just appends that number to the list codes=[].</p>
  
  <p>What if the user enters a 3? I know that 3 is less then the next power of 2 with is 4 and is the previous 2 numbers added together. How can I split that 3 up into a 1 and a 2 and append both those values into the codes=[] List?</p>