I have a hex-string made from a unicode string with that function:
def toHex(s): res = \"\" for c in s: res += \"%02X\" % ord(c) #at least 2
Can't be done. Using %02X loses too much information. You should be using something like UTF-8 first and converting that, instead of inventing a broken encoding.
%02X
>>> u"Knödel".encode('utf-8').encode('hex') '4b6ec3b664656c'