Advertisement
NickG

Untitled

Dec 5th, 2013
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.35 KB | None | 0 0
  1. def int_to_varint(val):
  2.     total = val&0x7F
  3.     val >>= 7
  4.     shift = 8
  5.     while val:
  6.         bits = val&0x7F
  7.         val >>= 7
  8.         total = ((0x80|bits)<<shift)|total
  9.         shift += 8
  10.     return total
  11.  
  12. def varint_to_int(varint):
  13.     total = 0
  14.     shift = varint.bit_length()//8
  15.     for i in range(shift):
  16.         bits = varint&0x7F
  17.         varint >>= 8
  18.         total = (bits<<(7*i))|total
  19.     return total
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement