简体   繁体   中英

How to XOR a list of binary string with just a string in python

ListOfBinString  = ['00110110101000111010000011000100000010000110001011', '10110111100111111110001111100011100101011010111010', '11101000111010100101111111001010000110100110110110', '11101111010111000101111111001010101001100101111011']

binString = "10000010001110010011101001010000110000110011100000"

#Code sample

string = ""
for i in ListOfBinString:
    string = string + hex(int(i)^ int(binString))
print(string)

My goal is to Xor each string in ListOfBinString using binString, then return all the Xored value as a single string.

Convert from string to int with base 2 and then do the XOR operation

string = ""
for i in ListOfBinString:
    string = string + hex(int(i,2)^int(binString,2))
print(string)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM