我正在使用一段代码来转换例如这个 256 个整数的列表:
a = [50, 177, 75, 135, 123, 30, 218, 164, 42, 29, 144, 38, 241, 154, 172, 142, 27, 1, 109, 198, 200, 230, 88, 235, 4, 86, 34, 112, 50, 116, 10, 156, 136, 48, 187, 62, 52, 223, 118, 73, 95, 238, 66, 62, 184, 234, 52, 7, 143, 108, 59, 12, 192, 91, 12, 157, 125, 173, 32, 42, 64, 184, 31, 41, 191, 145, 137, 89, 56, 16, 91, 219, 123, 231, 219, 9, 43, 193, 187, 5, 9, 94, 100, 86, 67, 232, 70, 35, 105, 76, 101, 176, 179, 113, 69, 33, 208, 216, 185, 255, 41, 104, 169, 191, 20, 2, 64, 117, 8, 157, 44, 252, 34, 38, 53, 120, 71, 68, 21, 209, 225, 167, 22, 186, 224, 176, 74, 149, 170, 69, 198, 31, 56, 166, 219, 68, 102, 65, 31, 141, 75, 232, 132, 61, 49, 55, 49, 26, 175, 50, 26, 171, 132, 247, 88, 53, 254, 133, 98, 88, 27, 116, 106, 163, 144, 145, 180, 204, 187, 44, 142, 163, 148, 174, 64, 174, 91, 245, 107, 193, 100, 183, 89, 15, 71, 161, 44, 172, 194, 169, 173, 2, 66, 105, 77, 99, 249, 205, 242, 195, 113, 138, 152, 230, 109, 173, 0, 118, 66, 58, 208, 70, 212, 204, 155, 132, 129, 35, 238, 83, 203, 141, 159, 30, 246, 77, 229, 21, 229, 18, 191, 33, 15, 26, 77, 63, 135, 34, 147, 220, 91, 144, 11, 218, 209, 132, 233, 253, 75, 15, 14, 208, 252, 228, 181, 55]
到这个 512 个字符的字符串:
b = '32b14b877b1edaa42a1d9026f19aac8e1b016dc6c8e658eb0456227032740a9c8830bb3e34df76495fee423eb8ea34078f6c3b0cc05b0c9d7dad202a40b81f29bf91895938105bdb7be7db092bc1bb05095e645643e84623694c65b0b3714521d0d8b9ff2968a9bf14024075089d2cfc22263578474415d1e1a716bae0b04a95aa45c61f38a6db4466411f8d4be8843d3137311aaf321aab84f75835fe8562581b746aa39091b4ccbb2c8ea394ae40ae5bf56bc164b7590f47a12cacc2a9ad0242694d63f9cdf2c3718a98e66dad0076423ad046d4cc9b848123ee53cb8d9f1ef64de515e512bf210f1a4d3f872293dc5b900bdad184e9fd4b0f0ed0fce4b537'
执行此转换的代码是:
import binascii
b = binascii.hexlify(bytearray(a)).decode()
我需要换一种方式,从字符串到整数列表。我认为这binascii.unhexlify
肯定会有用,我已经尝试过了,但仍然无法弄清楚这种转换的逆是什么。有任何想法吗?