# Python built-in Functions bin () Oct () to implement the transform _python

Source: Internet
Author: User
Use Python built-in functions: Bin (), Oct (), int (), Hex () to implement the transform.
Look at the description of these built-in functions in the official Python documentation:
bin (x)
Convert an integer number to a binary string. The result is a valid Python expression. If x is isn't a Python int object, it has to define a __index__ () method This returns an integer.
Oct (x)
Convert an integer number to a octal string. The result is a valid Python expression. If x is isn't a Python int object, it has to define a __index__ () method This returns an integer.
int ([number | string[, Base]])
Convert a number or string to an integer. If no arguments are given, return 0. If A is given, return number.__int__ (). Conversion of floating point numbers to integers truncates towards zero. A string must is a Base-radix integer literal optionally preceded by ' + ' or '-' (with no spaces in between) and optionally Surrounded by whitespace. A base-n literal consists of the digits 0 to n-1, with ' a ' to ' Z ' (or ' a ' to ' Z ') has values to 35. The default base is 10. The allowed values are 0 and 2-36. Base-2,-8, and-16 literals can is optionally prefixed with 0b/0b, 0o/0o, or 0x/0x, as and integer literals in code. Base 0 means to interpret exactly as a-code literal, so this actual base is 2, 8,, or, and so, int (' 010 ', 0) Is isn't legal, while INT (' 010 ') is, as ok as int (' 010 ', 8).
Hex (x)
Convert an integer number to a hexadecimal string. The result is a valid Python expression. If x is isn't a Python int object, it has to define a __index__ () method This returns an integer.
 ↓ 2 in-system 8 in-system 10 in-system 16 in-system 2 in-system - Bin (int (x, 8)) Bin (int (x, 10)) Bin (int (x, 16)) 8 in-system Oct (int (x, 2)) - Oct (int (x, 10)) Oct (int (x, 16)) 10 in-system int (x, 2) int (x, 8) - int (x, 16) 16 in-system Hex (int (x, 2)) Hex (int (x, 8)) Hex (int (x, 10)) -

The return values for Bin (), Oct (), Hex () are strings and are prefixed with 0b, 0o, 0x, respectively.
Related Keywords:
Related Article

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.