Python 2, 8, 10, 16 conversion between binary

Source: Internet
Author: User

Binary conversion has always been a headache for beginners, the following is a simple list of how each of the binary is converted.

# print (' 2-->8: ', Oct (int (' 0b1010 ', 2))     # 2-10-8# print (' 2-->10: ', int (' 0b1010 ', 2))          # 2-10# print (' 2--& GT;16: ', Hex (int (' 0b1010 ', 2))     # 2-10-16# print (' 8-->2: ', Bin (int (' 0o12 ', 8))        # 8-10-2# print (' 8-->10: ', int (' 0o12 ', 8)            # 8-10# print (' 8-->16: ', Hex (int (' 0o12 ', 8)))       # 8-10-16# print (' 10-->2 ', bin                    ) # 10-2# print (' 10-->8 ', Oct (Ten))                    # 10-2# print (' 10-->16 ', hex)                   # 10-16# print (' 16-->2: ', Bin (int (' 0xa ', +))       # 16-10-2# print (' 16-->8: ', Oct (int (' 0xa ', +)))       # 16-10-8# print (' 16-->10: ', int (' 0xa ', 16)           # 16-10 "    2-->8:  0o12    2-->10:10    2-->16:0xa    8-->2:0b1010 8-- >10:10    8-->16:0xa    10-->2 0b1010    10-->8 0o12    10-->16 0xa    16-->2:0b1010    16-->8:0o12    16-->10:10 ""

  

Conversion between Python 2, 8, 10, and 16

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.