Last active
January 5, 2016 14:16
-
-
Save smartinov/fe69caed43020311dbb7 to your computer and use it in GitHub Desktop.
Microsoft Python HexToGuid and GuidToHex
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 hex_to_guid(hex): | |
swapper = lambda A, n=2: [A[i:i + n] for i in range(0, len(A), n)] | |
segments = [hex[0:8], hex[8:12], hex[12:16], hex[16:20], hex[20:]] | |
for i in xrange(3): | |
segments[i] = "".join(list(reversed(swapper(segments[i])))) | |
return "-".join(segments) | |
def guid_to_hex(guid): | |
swapper = lambda A, n=2: [A[i:i + n] for i in range(0, len(A), n)] | |
segments = [guid[0:8], guid[9:13], guid[14:18], guid[19:23], guid[24:]] | |
for i in xrange(3): | |
segments[i] = "".join(list(reversed(swapper(segments[i])))) | |
return ''.join(segments) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment