title: Negative number causes VarInt's encoding function to crash
body: <p>I try to implement the function below in Python but as soon as I enter a negative number the function crashes. Does anyone understand why?</p>
  
  <pre class="lang-java prettyprint-override"><code>public static void writeVarInt(int value) {
      do {
          byte temp = (byte)(value &amp; 0b01111111);
  
          value &gt;&gt;&gt;= 7;
          if (value != 0) {
              temp |= 0b10000000;
          }
          writeByte(temp);
      } while (value != 0);
  }
  </code></pre>
  
  <p>Here my function : </p>
  
  <pre class="lang-py prettyprint-override"><code>def write_varint(array, data):
      first_pass = True
      while data != 0 or first_pass:
          first_pass = False
          temp = (data &amp; 0b01111111)
          data &gt;&gt;= 7
  
          if data != 0:
              temp |= 0b10000000
  
          print(temp)
  
          write_byte(array, temp)
  
  def write_byte(array, data):
      write_bytes(array, struct.pack('&gt;b', data))
  
  def write_bytes(array, source_bytes):
      for byte in source_bytes:
          array.append(byte)
  
  </code></pre>