title: Most Significant Byte Calculation
body: <p>I am trying to implement a larger cipher problem, and I am running into an issue I don't quite understand when taking the Most Significant Byte (not bit).</p>
  
  <p>To turn an int into a byte I am using:</p>
  
  <pre><code>def binary(i):
      if i == 0:
          return "0"
      s = ''
      while i:
          if i &amp; 1 == 1:
              s = "1" + s
          else:
              s = "0" + s
          i &gt;&gt;= 1
      return s 
  </code></pre>
  
  <p>I am pretty sure the above is correct, it works with my test numbers. To then extract the Most Significant Byte I am using:</p>
  
  <pre><code>def msb(i):
      a = binary(i)
      b = a[0:7]
      c = int(b,2)
      return c
  </code></pre>
  
  <p>However, this seems to return a number half what I would expect. Am I wrong in thinking you can get the most significant byte by just taking the first 8 bits, or am I missing something else silly?</p>