How to perform base conversion in python
1. Convert decimal to binary (bin)
First, let’s look at how to convert a decimal into binary. We can use python’s built-in method bin
1 2 |
|
Output
1 |
|
The binary in python starts with ob
Recommendation: " python video tutorial》
2. Convert decimal to octal (oct)
Let’s take a look at converting decimal to octal using the method oct(dec )
1 2 |
|
Output
1 |
|
3. Convert decimal to hexadecimal (hex)
Then convert decimal to hexadecimal, also using python’s built-in The method performs hex(dec)
1 2 |
|
output hexadecimal
1 |
|
4, binary conversion to decimal
1 2 |
|
output
1 |
|
5 , Convert octal to binary
Similar to the method of converting octal to binary
1 2 |
|
Output
1 |
|
6. Convert 16 to 10
Finally let’s look at the conversion of hexadecimal into decimal
1 2 |
|
For more Python tutorials, please pay attention to PHP Chinese website!
The above is the detailed content of How to perform hexadecimal conversion in python. For more information, please follow other related articles on the PHP Chinese website!