title: How is this code converting binary to integer values using ord()?
body: <pre><code>B = '1101'
  I = 0
  while B != '':
    I = I * 2 + (ord(B[0]) - ord('0'))
    B = B[1:]
  </code></pre>
  <p>This code convert binary to integer using <code>ord</code> function in python.
  Mathematical conversion for this case is <code>1 * 2^3 + 1 * 2^2 + 0 * 2^1 + 1 * 2^0 = 13</code> (answer for the given input).
  I am also not expecting the translation code of this math. but I would like to know how the given code conforms/translates to the math logic to give the desired result. could someone explain the  math/logic behind the code?</p>