I just came across your post about hex output. The following Python commands work for me: >>> hex(65)[2:] '41' >>> import string >>> string.zfill(hex(65)[2:],4) '0041' >>> The second parameter of string.zfill() specifies the number of digits you want in the string. If there are fewer digits, the function pads zeros to the left.