How to convert hex string to hex number?

前端 未结 8 1206
孤独总比滥情好
孤独总比滥情好 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条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-09 18:13

    Your code works for me, no apostrophes added.

    Python 2.6.4 (r264:75708, Oct 26 2009, 08:23:19) [MSC v.1500 32 bit (Intel)] on win32
    Type "help", "copyright", "credits" or "license" for more information.
    >>> my_number = 16
    >>> hex_no = hex(my_number)
    >>> print hex_no
    0x10
    >>> _
    

    Note, by the way, that there's no such thing as a "hex number". Hex is just a way to specify a number value. In the computer's memory that number value is usually represented in binary, no matter how it's specified in your source code (decimal, hex, whatever).

    Cheers & hth.,

    – Alf

提交回复
热议问题