Python 十进制转二进制、八进制、十六进制

Python 3 教程 · 2019-02-12 12:59:28

以下代码用于实现十进制转二进制、八进制、十六进制:

实例(Python 3.0+)

# -*- coding: UTF-8 -*- # Filename : test.py # author by : www.codercto.com # 获取用户输入十进制数 dec = int(input("输入数字:")) print("十进制数为:", dec) print("转换为二进制为:", bin(dec)) print("转换为八进制为:", oct(dec)) print("转换为十六进制为:", hex(dec))

执行以上代码输出结果为:

python3 test.py 
输入数字:5
十进制数为:5
转换为二进制为: 0b101
转换为八进制为: 0o5
转换为十六进制为: 0x5
python3 test.py 
输入数字:12
十进制数为:12
转换为二进制为: 0b1100
转换为八进制为: 0o14
转换为十六进制为: 0xc

点击查看所有 Python 3 教程 文章: https://www.codercto.com/courses/l/10.html

查看所有标签

Bandit Algorithms for Website Optimization

Bandit Algorithms for Website Optimization

John Myles White / O'Reilly Media / 2013-1-3 / USD 19.99

This book shows you how to run experiments on your website using A/B testing - and then takes you a huge step further by introducing you to bandit algorithms for website optimization. Author John Myle......一起来看看 《Bandit Algorithms for Website Optimization》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具