-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcheck_utils.py
More file actions
15 lines (15 loc) · 937 Bytes
/
check_utils.py
File metadata and controls
15 lines (15 loc) · 937 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
from config.utils import *
if __name__ == '__main__':
# 原始的十六进制字符串,包含空格
# hex_str = "00 00 02 01 01 01 01 01 01 01 01 01 80 00 00 07 57 7b 00 24 00 00 00 01 c0 a8 08 00 ff ff ff 00 03 00 00 01"
# hex_str = "00 00 02 01 01 01 01 01 01 01 01 01 80 00 00 04 5d 78 00 24 00 00 00 01 c0 a8 08 00 ff ff ff 00 03 00 00 01"
# hex_str = "00 00 02 01 02 02 02 02 02 02 02 02 80 00 00 00 00 00 00 18 00 00 00 00"
# 移除空格并转换为字节串
# 这里假设hex_str已经是清理过的,只包含有效的十六进制字符
# 如果hex_str中还包含其他无效字符,需要进一步清理
clean_hex_str = hex_str.replace(" ", "") # 移除所有空格
bytes_str = bytes.fromhex(clean_hex_str)
num = fletcher_checksum(bytes_str,16)
# num = calculate_checksum(bytes_str)
# num = fletcher16_checksum(bytes_str)
print_bytes(all_to_bytes(num,2))