Python的bit_length函数来二进制的位数方法

作者:杰瑞26 时间:2022-06-25 00:35:58 

自Python3.1中,整数bit_length方法允许查询二进制的位数或长度。

常规做法:


>>> bin(256)
'0b100000000'

>>> len(bin(256)) - 2
9

>>>

使用函数:


>>> bin(256), (256).bit_length()
('0b100000000', 9)

>>> X = 99

>>> bin(X), X.bit_length()
('0b1100011', 7)

>>>

来源:https://blog.csdn.net/Jerry_1126/article/details/82917224

标签:Python,bit,length,二进制,位数
0
投稿

猜你喜欢

  • oracle 函数

    2010-07-23 13:06:00
  • 解决PHP 7编译安装错误:cannot stat ‘phar.phar’: No such file or directory

    2023-09-05 06:07:44
  • (X)HTML的文档结构

    2008-06-30 12:25:00
  • SQL Server 2005中插入XML数据方法

    2008-05-26 11:56:00
  • php报错502badgateway解决方法

    2023-11-22 13:12:06
  • 在windows下 1045 access denied for user

    2010-03-04 11:44:00
  • 将有安全问题的SQL过程删除,比较全面

    2007-08-06 14:46:00
  • XHTML1.0与HTML兼容指引16条[译]

    2009-06-10 14:45:00
  • 详解Python中for循环是如何工作的

    2021-07-04 17:41:40
  • Python入门教程3. 列表基本操作【定义、运算、常用函数】 <font color=red>原创</font>

    2023-07-15 13:09:19
  • 分享一个超好用的php header下载函数

    2023-09-03 21:31:43
  • Python多进程同步简单实现代码

    2021-05-17 23:48:04
  • Python实现读取Properties配置文件的方法

    2021-01-05 17:28:21
  • Python实现截图生成符合markdown的链接

    2021-07-09 10:18:22
  • 可以用ASP生成由客户浏览器处理的客户端脚本吗?

    2009-11-01 18:06:00
  • PHP实现批量生成App各种尺寸Logo

    2023-07-23 03:59:59
  • 服务器响应HTTP的类型ContentType大全

    2007-10-23 10:21:00
  • 一行两列背景自适应的简单写法 DIV+CSS

    2008-07-15 12:51:00
  • 异步加载Google Adsense 更新到Wordpress 2.62

    2008-09-11 13:09:00
  • Go web入门Go pongo2模板引擎

    2023-07-22 22:16:43
  • asp之家 网络编程 m.aspxhome.com