20 lines
542 B
Python
20 lines
542 B
Python
|
|
|
|
def hex_val_str(val,bytes_to_fill,prefix='0x'):
|
|
ret_str = ''
|
|
if bytes_to_fill == 1:
|
|
ret_str = '{2}{0:0{1}X}'.format(val,2,prefix)
|
|
elif bytes_to_fill == 2:
|
|
ret_str = '{2}{0:0{1}X}'.format(val,4,prefix)
|
|
elif bytes_to_fill == 4:
|
|
ret_str = '{2}{0:0{1}X}'.format(val,8,prefix)
|
|
return ret_str
|
|
|
|
def hex_bytes_to_str(hex_bytes,prefix='0x',sep=' '):
|
|
hex_str=''
|
|
for data in hex_bytes:
|
|
hex_str = hex_str + hex_val_str(data,1,prefix) + sep
|
|
return hex_str
|
|
|
|
def hex_str_to_bytes(hex_str):
|
|
return bytes.fromhex(hex_str) |