Add hex representation thing

This commit is contained in:
Elliot Nunn 2019-08-17 09:12:53 +08:00
parent b5b9c6e073
commit c6e657fa05
1 changed files with 18 additions and 0 deletions

18
db68.py Normal file
View File

@ -0,0 +1,18 @@
# This might grow into a MainCode function-matching system?
import binascii
# ,ABCD,EF01,
def commastring(binary):
ugly = binascii.hexlify(binary).upper()
num = len(ugly) + len(ugly) // 4 + 1
fugly = bytearray(b',' * num)
fugly[1::5] = ugly[0::4]
fugly[2::5] = ugly[1::4]
fugly[3::5] = ugly[2::4]
fugly[4::5] = ugly[3::4]
while fugly.endswith(b',,'): fugly.pop(-1)
return fugly.decode('ascii')
# import sys
# print(commastring(sys.argv[1].encode('utf-8')))