Python Learning--in-process conversion

Source: Internet
Author: User

Commonly used in the system include: binary, octal, decimal and hexadecimal, they are the difference between the number of operations is a few in a bit.

1. Decimal Turn binary

Command: Bin ()

A = 8print (Bin (a))

Operation Result:

0b1000

Calculation:

binary = decimal decimal + binary

8 1000

8/2 + 0 0 1 0 0 0

4/2 + 0 0 2^3 x1 + 2^2 x0 + 2^1 x0 + 2^0 x 0

2/2 + 0 0

1/2 more than 1

Results: 1000

2. Decimal to Octal

Command: Oct ()

A =print(Oct (a))

Operation Result:

0o22

Calculation:

octal = Decimal decimal = octal

Ditto: 8^1 x 2 + 8^0 x 2

3. Decimal Turn hex

Command: Hex ()

A =print(Hex (a))

Operation Result:

0x26

Calculation:

Hex: 1-9 a-f

decimal = hexadecimal hexadecimal = = Decimal

Ibid.: Ibid.: 16^1 x 2 + 16^0 x 6

38/16 + 6 6

2/16 + 2 2

Results: 26

4. Binary conversion decimal, octal, hex

command: Int ()

A = ' 11100 'print(' decimal:', int (a,2),' octal ', int (b,8), ' hexadecimal ', int (c,16))

Note: The converted variable format is: string format

Operation Result:

Decimal: 288 binary 46,726 binary 69888

5. Character conversion numeric numeric conversion character

Command: Ord () "must be a character" Chr () "must be a number" (Asill code)

# Number = = character (Asill code)A =print(Chr (a))#'n ' Print (Ord (b))

Operation Result:

N110

Python Learning--in-process 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.