update hex handling code for python 3