python

@staticmethod
    def HexStringToString(value):
        """
        Name     :HexStringToString
        Function :将16进制的字符串转化成 实际的字符串
        Parameter:value(string) -- 原始数据
        Return   :retValue(string)-- 转换后的值
        Records  :
        Huang Jichao    2009-06-17    Create
        """

        retValue = ""
        iLength = 0
        bzHex = []

        if (len(value) == 0):
            return retValue

        iLength = len(value)
        for i in range(0, iLength, 2):
            bzHex.append(0)
            bzHex.append(0)
            temp = value[i:i + 2].lower()
            bzHex[0] = ord(temp[0])
            bzHex[1] = ord(temp[1])

            if ((bzHex[0] <= (48 + 10))):
                bzHex[0] = (bzHex[0] - 48)
            elif (bzHex[0] >= ord('a')):
                bzHex[0] = (10 + bzHex[0] - ord('a'))

            if ((bzHex[1] <= (48 + 10))):
                bzHex[1] = (bzHex[1] - 48)
            elif (bzHex[1] >= ord('a')):
                bzHex[1] = (10 + bzHex[1] - ord('a'))

            iTemp = bzHex[0] * 16 + bzHex[1]
            if (0 == iTemp):
                break
            retValue = retValue + chr(iTemp)

        return retValue

    @staticmethod
    def HexStringToInteger(strHex):
        """
        Name     :HexStringToInteger
        Function :
        Parameter:strHex(string)
        Return   :retValue(string)
        Records  :
        Huang Jichao    2009-06-17    Create
        """
       
        retValue = ""
        bzHex = []
        iTemp = 0
        bTemp = 0

        strHex = strHex.lower()
        for i in strHex:
            bzHex.append(ord(i))

        for i in range(len(strHex)):
            if (bzHex[i] <= (48 + 10)):
                bTemp = bzHex[i] - 48
            elif (bzHex[i] >= ord('a')):
                bTemp = 10 + bzHex[i] - ord('a')

            iTemp = (iTemp + bTemp * pow(16, len(strHex) - i - 1))

        retValue = str(iTemp)
        return retValue

你可能感兴趣的:(python)