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://codercto.com/courses/l/10.html

查看所有标签

Large-Scale Inference

Large-Scale Inference

Bradley Efron / Cambridge University Press / 2010-8-5 / GBP 48.00

We live in a new age for statistical inference, where modern scientific technology such as microarrays and fMRI machines routinely produce thousands and sometimes millions of parallel data sets, each ......一起来看看 《Large-Scale Inference》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换