Python 内置函数进制转换的用法(十进制转二进制、八进制、十六进制)
2024-08-31 09:28:36
↓ | 2进制 | 8进制 | 10进制 | 16进制 |
2进制 | - | bin(int(x, 8)) | bin(int(x, 10)) | bin(int(x, 16)) |
8进制 | oct(int(x, 2)) | - | oct(int(x, 10)) | oct(int(x, 16)) |
10进制 | int(x, 2) | int(x, 8) | - | int(x, 16) |
16进制 | hex(int(x, 2)) | hex(int(x, 8)) | hex(int(x, 10)) | - |
格式化输出
>>> x = 1234
>>> bin(x)
'0b10011010010'
>>> oct(x)
'0o2322'
>>> hex(x)
'0x4d2' //如果你不想输出0b , 0o 或者0x 的前缀的话,可以使用format() 函数 >>> format(x, 'b')
'10011010010'
>>> format(x, 'o')
'2322'
>>> format(x, 'x')
'4d2'
最新文章
- xinetd cpu 100%
- eclipse建立springMVC 简单项目
- 当shiro做成动态URL管理时出现循环注入BeanCurrentlyInCreationException的问题解决方法
- TeXmacs 中输入狄拉克 braket 符号
- Docker tips
- SVN库迁移过程总结
- c# 高效分页只需一个dll实例
- JQuery(三)——操作HTML和CSS内容
- 百度APP移动端网络深度优化实践分享(一):DNS优化篇
- Python第八天 模块 包 全局变量和内置变量__name__ Python path
- Android学习之基础知识九 — 数据存储(持久化技术)之SQLite数据库存储
- uoj233/BZOJ4654/洛谷P1721 [Noi2016]国王饮水记 【dp + 斜率优化】
- confusing c++ 重写 与 重定义 记录1
- Swift3 获取当前连接WIFI名称
- Windows下搭建appium(Android版)
- 解决:在pom.xml处理添加testng依赖之外,需对testng进行关联
- python【数据类型:集合】
- K-Means &; Sequential Leader Clustering
- Alpha-9
- IIS 搭建过程