Python脚本

反转字节序

def reverse_byte_order(hex_str):
    # 将十六进制字符串分割成字节
    bytes_list = [hex_str[i:i+2] for i in range(0, len(hex_str), 2)]
    
    # 反转字节顺序
    reversed_bytes = bytes_list[::-1]
    
    # 将反转后的字节列表拼接成新的十六进制字符串
    reversed_hex = ''.join(reversed_bytes)
    
    return reversed_hex

# 测试数据
original_hex = "a2137a23f8cbd2"
reversed_hex = reverse_byte_order(original_hex)

print("Original Hex: ", original_hex)
print("Reversed Hex: ", reversed_hex) # d2cbf8237a13a2

  

posted @ 2024-12-20 00:46  韩凯1202  阅读(2)  评论(0编辑  收藏  举报