I know this question has been asked before, and some of the suggestions seem to be about needing a b to make the string a byte literal. However, im passing hex code to the function as 0x414243 to save it as ABC.
def _pack(_data, size):
numofbytes = size/8
print("Chars Expected: " + str(numofbytes))
formatString = "{}s".format(int(numofbytes))
print("Formatted String:" + formatString)
struct.pack(formatString,_data)
_pack(0x414243,24)
I'm not sure what to change here, im wondering if its a problem with how im using formatstring variable. I want the function to be able to work out how many chars are in the passed data from the size and in this case 24 bits = 3 bytes so it formats 3s and passes 0x414243 to convert to ABC.
Can anyone advise how to get past the error.