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.