title: Converting Binary to Decimal in python (without built in binary function)
body: <p>Alrighty, first post here, so please forgive and ignore if the question is not workable;</p>
  
  <p>Background:
  I'm in computer science 160.  I haven't taken any computer related classes since high school, so joining this class was a big shift for me. It all seemed very advanced.  We have been working in Python and each week we are prompted to write a program.  </p>
  
  <p>I have been working with this problem for over a week and am having a hard time even starting.<br>
  The prompt is to read an integer containing only 1's and 0's,
  process the binary number digit by digit and report the decimal equivalent.  Now, I have gotten some tips from a classmate and it sent me at least in a direction.  </p>
  
  <p>Set up a couple of counters;
  using the <code>%</code> operator to check the remainder of the number divided by 2, and slicing off the last number (to the right) to move on to and process the next digit.  </p>
  
  <p>I am having an incredibly hard time wrapping my head around what formula to use on the binary digits themselves which will convert the number to decimal.  </p>
  
  <pre><code>setbitval = 0
  counter = 0
  
  user = int(input("enter a binary value. "))
  
  if user % 2 == 1:
          user = (user/10) - .1
          setbitval += 1
  </code></pre>
  
  <p>This is all I've got so far.. My thinking is getting in the way.  I've searched and searched, even through these forums.</p>
  
  <p>
  Any information or thoughts are extremely appreciated,<br/>
  T
  </p>
  
  <p>Edit: okay guys, everyone's help has been extremely useful but I'm having a problem checking if the user input is not a binary number.  </p>
  
  <pre><code>for i in reversed(bits):   
  decimal += 2**counter * int(i)
  
  counter += 1    
  </code></pre>
  
  <p>This is the formula someone here gave me and I've been trying different iterations of "for i in bits:  if i in bits: != 0 or 1" and also "if i in bits: >= 1 or &lt;=0".<br>
  Any thoughts?</p>