Skip to content

Instantly share code, notes, and snippets.

@brake
Created April 3, 2015 08:16
Show Gist options
  • Save brake/9522e1af18545c5aa2f9 to your computer and use it in GitHub Desktop.
Save brake/9522e1af18545c5aa2f9 to your computer and use it in GitHub Desktop.
Swap nibbles python
def swap_nibbles(s):
"""Swap nibbles in a hex string.
len(s) must be even otherwise ValueError will be raised.
"""
if len(s) % 2:
raise ValueError()
return ''.join([y+x for x,y in zip(*[iter(s)] * 2)])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment