Conversion between different Python operating systems

Source: Internet
Author: User
Binary 0b101 uses numbers 0 and B to indicate binary numbers. if a number greater than or equal to 2 is displayed, SyntaxError is thrown. octal 0711 indicates the number of octal numbers.

Different hexadecimal

Binary 0b101

If a number greater than or equal to 2 is displayed, a SyntaxError error is thrown.

Octal 0711

If a number greater than or equal to 8 is displayed, a SyntaxError error is thrown.

Decimal 123

Letters are not allowed for normal display

Hexadecimal 0x15

If the hexadecimal number is indicated by the number 0 and subtitle x headers, other values 0-9, abcdef, and ABCDEF may cause a SyntaxError error.

Built-in functions after python 2.6

# Convert from 10 to 2

>>> bin(10)'0b1010'

# Convert from 2 to 10

>>> int("1001",2)9

# Convert from 10 to 16

>>> hex(10)'0xa'

# Hexadecimal to hexadecimal

>>> int('ff', 16)255
>>> int('0xab', 16)171

# Convert decimal to octal

>>print("%o" % 10)>>12

# Hexadecimal to binary

>>> bin(0xa)'0b1010'>>>

#10 to 8

>>> oct(8)'010'

# Binary to hexadecimal

>>> hex(0b1001)'0x9'

In addition, in the interactive interpreter environment, python automatically converts different hexadecimal values to decimal values for calculation.

>>> 0b101 + 0711 + 123 + 0x15 606

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.