How to convert hex string to hex number?

前端 未结 8 1224
孤独总比滥情好
孤独总比滥情好 2020-12-09 17:36

I have integer number in ex. 16 and i am trying to convert this number to a hex number. I tried to achieve this by using hex function but whenever you provide a integer numb

8条回答
  •  猫巷女王i
    2020-12-09 17:53

    I think here most of the answers were misinterpreted or they understood the question wrongly.

    To answer to your question it is IMPOSSIBLE to convert resultant string representation of Hex data to Hex numbers(integer representation).

    Because, when you convert an integer to hex by doing following

    >>> a = hex(34)
    >>> print type(a)
    
    >>> print a
    0x22
    >>> a
    '0x22'
    

    And some answers were confused here,

    >>> print a
    0x22
    >>> a
    '0x22'
    

    When you type print a in interpreter it will result the string data WITHOUT quotes and If you simply type the variable name without using print statement then it would print the string data WITH single/double quotes.

    Though the resultant value is Hex data but the representation is in STRING.

    As per Python docs you cannot convert to Hex number as I told earlier.

    Thanks.

提交回复
热议问题