Skip to content

Instantly share code, notes, and snippets.

@mrdomino
Last active March 5, 2022 06:13
Show Gist options
  • Save mrdomino/3ed5d5c85725c470ee7da73e70549f13 to your computer and use it in GitHub Desktop.
Save mrdomino/3ed5d5c85725c470ee7da73e70549f13 to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
import fileinput
import re
def main():
for line in fileinput.input():
if not re.search(r'^[0-9a-fA-F]+$', line):
continue
print('0x', end='')
line = line.strip().lstrip('0')
if not line:
print('0')
continue
n, m = divmod(len(line), 4)
if m:
print(line[:m].lower(), end='')
if n:
print('.', end='')
for i in range(n):
print(line[m + i * 4 : m + (i + 1) * 4].lower(), end='')
if i + 1 != n:
print('.', end='')
print()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment