Created
March 23, 2014 19:00
-
-
Save heikoheiko/9727917 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def int_to_big_endian(integer): | |
'''convert a integer to big endian binary string''' | |
if integer == 0: | |
return '' | |
s = '%x' % integer | |
if len(s) & 1: | |
s = '0' + s | |
return s.decode('hex') | |
def big_endian_to_int(string): | |
'''convert a big endian binary string to integer''' | |
string = string or '\x00' # cpp client encodes \x00 as '' | |
s = string.encode('hex') | |
return int(s, 16) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment