Newbie here.
I'm trying to get a hex XOR checksum of a string; and I have the following Python 2.7 code:
def getCheckSum(sentence):
calc_cksum = 0
for s in sentence:
calc_cksum ^= ord(s)
return str(hex(calc_cksum)).strip('0x')
print getCheckSum('SOME,1.948.090,SENTENCE,H,ERE')
Now this works fine as a dime EXCEPT for when the result contains 0
. If the final value is 02
or 20
, it will print only 2
. I thought about implementing a .zfill(2)
, but that would only be applicable for cases where 0
precedes the digit; therefore not reliable.
Any solution to why this might be and how to resolve it?