辅助工具_c语言hex数组和hex字符串转换

c语言hex数组和hex字符串转换

import os,sys

'''
example:
>python3 test.py 6677
0x66, 0x77
>python3 test.py 0x66,0x77
6677
>python3 test.py "0x66, 0x77"
6677
'''

str = sys.argv[1]
out = ''
if str.find('0x'):
    out = '0x'
    count = 0
    for c in str:
        out = out + c
        count = count + 1
        if count == len(str):
            break
        if count % 2 == 0:
            out = out + ', 0x'
else:
    str_list = str.split(',')
    for tmp in str_list:
        print(tmp)
        out = out + tmp[tmp.find('0x')+2:]

print(out)

hex逆序

import os,sys

'''
example:
>python3 test.py 6677
7766
'''

str = sys.argv[1]
out = ''
for i in range(0, len(str), 2):
    out = str[i:i+2] + out

print(out)

你可能感兴趣的:(辅助工具)