Python's functional module [3]--BINASCII conversion

Source: Internet
Author: User

binascii modules /binascii module

The Binascii module contains a number of conversion methods between binary and ASCII -encoded binary representations . You can refer to some built-in functions for binary conversions.

hexlify with the unhexlify

>>>ImportBinascii>>> A ='Hello World'>>> B =Binascii.b2a_hex (a) Traceback (most recent): File"<pyshell#2>", Line 1,inch<module>b=Binascii.b2a_hex (a) TypeError:'Str'Does notSupport the buffer interface>>> A = b'Hello World'>>> B =Binascii.b2a_hex (a)>>>Print(b) B'68656C6C6F20776F726C64'>>> B =binascii.hexlify (a)>>>Print(b) B'68656C6C6F20776F726C64'>>>Print(binascii.unhexlify (b)) b'Hello World'  

The above functions hexlify and B2a_hex are actually a function, it is recommended to use Hexlify. Its role is to return the hexadecimal representation of the binary data . The data for each byte is converted to the corresponding 2-bit hexadecimal representation. So the resulting string is twice times the length of the original data. A2b_hex and Unhexlify perform the reverse operation.

Related reading

1. Built-in functions

Python's functional module [3]--BINASCII conversion

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.