Last active
March 5, 2022 06:13
-
-
Save mrdomino/3ed5d5c85725c470ee7da73e70549f13 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
#!/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