#!/usr/bin/env python #coding=utf8 import binascii def hexConvertToString1(sumStringOfHex): hexArray = sumStringOfHex.split(' ') #print hexArray hexIntArray = [int(mHex, 16) for mHex in hexArray] hexString = '' #print "...." + str(hexIntArray) for mHex in hexIntArray: hexString += chr(mHex) return hexString def hexConvertToString2(sumStringOfHex): hexString = '' hexList = sumStringOfHex.replace('0x', '').split(' ') for mHex in hexList: hexString += binascii.a2b_hex(mHex) #a2b_hex: '31'->'1', '41'->'A', b2a_hex: 'A' -> '41' #print hexString return hexString if __name__ == "__main__": sumStringOfHex = "0x31 0x55 0x34 0x47 0x58 0x43 0x34 0x36 0x4b" print hexConvertToString1(sumStringOfHex) print hexConvertToString2(sumStringOfHex)