Python string Turn Hex__python

Source: Internet
Author: User

http://blog.csdn.net/hdutigerkin/article/details/6687817



Call the Python built-in int () function to convert the string to a number. The following is a demonstration of the operation in the Python interpreter programming environment:

Converts a hexadecimal string to a decimal number:
Python code
>>> print int (' FF ', 16)
255

>>> print int (' FF ', 16)
255

Converts a decimal number to a string in hexadecimal notation, which invokes the built-in hex () function:
Python code
>>> print Hex (255)
0xFF

>>> print Hex (255)
0xFF

Call the B2a_hex () function in the Binascii module to represent ASCII-encoded text in hexadecimal:
Python code
>>> print Binascii.b2a_hex (' A ')
41

>>> print Binascii.b2a_hex (' A ')
41

Conversely, you can replace text in hexadecimal with ASCII-encoded text:
Python code
>>>print Binascii.a2b_hex (' 41 ')

A

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.