Parse WAP-230 "variable length unsigned integers"
To get the bits out of a byte without converting to a string and back again, use Python's bitwise operations and shift operations. To get the high bit of a byte, shift it right by 7 bits:

&gt;&gt;&gt; data = open('/dev/urandom', 'rb').read(128)
&gt;&gt;&gt; data[0]
193
&gt;&gt;&gt; data[0] &gt;&gt; 7
1


To get the low seven bits of a byte, mask against 0b1111111 (that is, 127):

&gt;&gt;&gt; data[0] &amp; 127
65


Finally, if we maintain a running value for content_length, we can extend it with these seven bits of payload by taking the running value, shifting it left by 7 bits and or-ing with the payload. In summary:

content_length = 0
while True:
    byte = self.data[curr_index]
    curr_index += 1
    content_length = (content_length &lt;&lt; 7) | (byte &amp; 127)
    if byte &gt;&gt; 7 == 0:
        break