Analysis of examples of Python common numbering conversion

Source: Internet
Author: User
Tags in python

This article mainly introduces Python common system conversion, examples of binary, octal, decimal and hexadecimal conversion skills, the need for friends can refer to the

1. Rounding System

Binary in Python starts with a 0b:

For example: 0B11 represents 3 of the decimal

The 8 binary starts with 0:

For example: 011 means decimal 9

The 16 binary starts with 0x:

For example: 0x11 represents 17 of the decimal

or write an X-B.

2. Conversion of functions

?

1, 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 #10进制转为2进制 >>> Bin (a) ' 0b1010 ' #2进制转为10进制 >>> int ("1001", 2) 9 #10进制转为16进制 >>> Hex 0xa ' #16进制到10进制 >>> int (' FF ', "255 >>> int (' 0xAB ') 171 #十进制转为八进制 >>print ("%o "%) > >12 #16进制到2进制 >>> Bin (0xa) ' 0b1010 ' >>> #10进制到8进制 >>> Oct (8) ' 010 ' #2进制到16进制 >>& Gt Hex (0b1001) ' 0x9 '

I hope this article will help you with your Python programming.

Related Article

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.