Guest User

Untitled

a guest
Jul 23rd, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. def encode_int(obj):
  2. ret = []
  3. if obj < 0:
  4. obj = abs(obj)
  5. neg = True
  6. else:
  7. neg = False
  8.  
  9. while obj:
  10. ret.append(obj & 0xFF)
  11. obj = obj >> 8
  12.  
  13. if neg:
  14. ret[0] = ret[0] | 0x80
  15.  
  16. ret.insert(0, (0x10 + len(ret)))
  17. return ''.join([chr(x) for x in ret])
Add Comment
Please, Sign In to add comment