Oct-31-2016, 06:59 AM
i am collecting simple code to make a variety of conversions in both python 2 and python 3 (e.g. same code works in both versions)
1. integer to hexadecimal: hex(myint)
2. string to hexadecimal: ???
3. string to integer: int(base64.b16encode(codecs.encode(mystr,'ascii')),16)
4. integer to string: codecs.decode(base64.b16decode(hex(myint).upper().split('L')[0].split('X')[1]),'ascii')
5. hexadecimal to integer: int(myhex,16)
6. hexadecimal to string: ???
any suggestions to make #4 simpler result must be a string (or unicode where that is usable like str), not an array of bytes, and code must work in both python 2 and python 3 any suggestions for #2 and #6 that would be better than combining other examples
1. integer to hexadecimal: hex(myint)
2. string to hexadecimal: ???
3. string to integer: int(base64.b16encode(codecs.encode(mystr,'ascii')),16)
4. integer to string: codecs.decode(base64.b16decode(hex(myint).upper().split('L')[0].split('X')[1]),'ascii')
5. hexadecimal to integer: int(myhex,16)
6. hexadecimal to string: ???
any suggestions to make #4 simpler result must be a string (or unicode where that is usable like str), not an array of bytes, and code must work in both python 2 and python 3 any suggestions for #2 and #6 that would be better than combining other examples