Python converts HEX to String, String to HEX high-low data processing
def Hex_Str16(data):
hex_str = '{:04X}'.format(data*100)
data_h, data_l = hex_str[0:2], hex_str[2:4]
return int(data_h, base=16), int(data_l, base=16)
def Hex_Str32(data):
hex_str = '{:08X}'.format(data*100)
data_1, data_2, data_3, data_4 = hex_str[:2], hex_str[2:4], hex_str[-4:-2], hex_str[-2:]
return int(data_1, base=16), int(data_2, base=16), int(data_3, base=16), int(data_4, base=16)
def Hex_Str64(data):
hex_str = '{:016X}'.format(data*100)
data_1, data_2, data_3, data_4, data_5, data_6, data_7, data_8 =hex_str[:2], hex_str[2:4], hex_str[4:6], hex_str[6:8],\
hex_str[-8:-6], hex_str[-6:-4], hex_str[-4:-2], hex_str[-2:]
return int(data_1, base=16), int(data_2, base=16), int(data_3, base=16), int(data_4, base=16),\
int(data_5, base=16), int(data_6, base=16), int(data_7, base=16), int(data_8, base=16)
def Str_Hex16(data):
Str= data[0]+data[1]
return int(Str,16),Str
def Str_Hex32(data):
Str = data[0] + data[1] + data[2] + data[3]
return int(Str,16),Str
def Str_Hex64(data):
Str = data[0] + data[1] + data[2] + data[3]+ data[4] + data[5] + data[6] + data[7]
return int(Str,16),Str
print(Hex_Str16(255))
print(Hex_Str32(255))
print(Hex_Str64(255))
data = ['0f','ff']
data_1 = ['00','00','0f','ff']
data_2 = ['00','00','00','00','00','00','0f','ff']
print(Str_Hex16(data))
print(Str_Hex32(data_1))
print(Str_Hex64(data_2))
The results are as follows
(99, 156)
(0, 0, 99, 156)
(0, 0, 0, 0, 0, 0, 99, 156)
(4095, '0fff')
(4095, '00000fff')
(4095, '0000000000000fff')
Read More:
- The conversion between [Python] bytes and hex strings.
- ‘Conversion failed when converting date and/or time from character string.DB-Lib error message 241,
- Python: How to Fix “Ord() expected string of length 1, but int found”
- Conversion between list and string array
- Solution to unbalanced load of multiple cards (GPU’s 0 card is too high) in Python model training (simple and effective)
- Java String.split () special character processing
- A repeated string is composed of two identical strings. For example, abcabc is a repeated string with length of 6, while abcba does not have a duplicate string. Given any string, please help Xiaoqiang find the longest repeated substring.
- Method of ignoring case in Python string comparison
- Python string prefix
- Coursera Using python to access Web data quiz 4
- Translate() and maketrans() methods of string in Python
- Python parallel processing makes full use of CPU to realize acceleration
- Python TypeError: not all arguments converted during string formatting [Solved]
- Solution to the warning of too low TDR value in new sp
- Local date time conversion in java8
- Conversion from hexadecimal to decimal
- Python data cleaning — delete failed images__ Simple version
- ParserError: Error tokenizing data. C error: EOF inside string starting at row 917
- Removing stop words —— Python Data Science CookBook
- python ValueError: source code string cannot contain null bytes