title: ValueError invalid literal for int() with base 2: '' in Python
body: <p>I'm trying to get a string, <code>jJ</code>, as input and then converting each character to it's 6 bit binary form using the mapping given in a and concatenating them and returning it in <code>mapFirst(string)</code>. That is, <code>jJ</code> becomes <code>100011001001</code>.</p>
  
  <p>In <code>binaryToLetter(string)</code> I'm taking the returned value and separating it into parts of 8 bits and converting it back to it's character form and concatenated. <code>100011001001</code> becomes <code>00001000</code> and <code>11001001</code>, which are then converted and joined to give <code>(backspace)É</code>.</p>
  
  <p>In my code, I'm getting the error :</p>
  
  <pre><code>Exception has occurred: ValueError
  invalid literal for int() with base 2: ''
  
    File "C:\Users\Sembian\Desktop\exc files new\Ex_Files_Learning_Python\Exercise Files\task_cs\task1.py", line 11, in &lt;genexpr&gt;
      return ''.join( str( int( (binNew[newLen:newLen-i]),2 ) ).replace('0b','').zfill(8) for i in range(0, newLen, n) )
  </code></pre>
  
  <p>The code I used is : </p>
  
  <pre><code>from textwrap import wrap
  a = ['A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','0','1','2','3','4','5','6','7','8','9','+','/']
  
  def mapFirst(string):
     return ''.join(str(bin(ord(chr(a.index(c))))).replace('0b','').zfill(6) for c in string)
  
  def binaryToLetter(binNew):
     newLen = len(str(binNew))          
     n=8
     return ''.join( str( int( (binNew[newLen:newLen-i]),2 ) ).replace('0b','').zfill(8) for i in range(0, newLen, n) )
  
  def main():
     k = 'jJ'
     print("the first binary value is: ",mapFirst(k))
     print("the final decoded value is: ", binaryToLetter(mapFirst(k)))
  
  if __name__ == "__main__":
    main()
  </code></pre>