Skip to content

Instantly share code, notes, and snippets.

@sammachin
Created February 5, 2015 13:00
Show Gist options
  • Select an option

  • Save sammachin/6c2b91d52b1052b0ec58 to your computer and use it in GitHub Desktop.

Select an option

Save sammachin/6c2b91d52b1052b0ec58 to your computer and use it in GitHub Desktop.
Convert 32bit binary int from BE to LE to Dec.
import struct
def convert(input):
v1 = struct.pack('>I', int(input, 2))
v2 = struct.unpack('<I', v1)
output = int(''.join(map(str,v2)))
return output
convert('01000000010000100000111100000000') # returns 1000000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment