看python官方说明学python-移位-bitewise
来源:互联网 发布:淘宝标题怎么写好 编辑:程序博客网 时间:2024/06/04 19:20
4.4.1. Bitwise Operations on Integer Types (数位操作)
Bitwise operations only make sense for integers. Negative numbers are treated as their 2’s complement value (this assumes a sufficiently large number of bits that no overflow occurs during the operation).
The priorities of the binary bitwise operations are all lower than the numeric operations and higher than the comparisons; the unary operation ~ has the same priority as the other unary numeric operations (+ and -).
This table lists the bitwise operations sorted in ascending priority (operations in the same box have the same priority):
说明——————————————————
将x转换成二进制,然后根据二进制转移位置。
x << n
5 << 2
将十进制5转换成二进制"0b101"然后向左移动两位,并补零成为"0b10100", 再转换成十进制。20
于是输出的结果是20
可以这样验证: 在python命令行里面输入bin(20)得到的结果是'0b10100', 0b的意思是binary 二进制。
5 >> 2 将'0b101'向右移动两位(再不溢出的情况下,就是说移动不超过其二进制长度),得到的结果是'0b1',十进制是1
于是输出1
x^y, 是x与y每一个位之间的 两个位都为真的时候,为假取0,其他的位值不变然后返回 值
x&y, 两个位都为真的时候,为真取1,所有值都这样,然后返回 值
x | y 两个位有一个为真,运算为真取1, 所有值都这样, 然后返回值
这些指的是各位之间的关系,
——————————————————————
Notes:
- Negative shift counts are illegal and cause a ValueError to be raised.
- A left shift by n bits is equivalent to multiplication by pow(2, n) without overflow check.
- A right shift by n bits is equivalent to division by pow(2, n) without overflow check.
- 看python官方说明学python-移位-bitewise
- 看python官方说明学python-tuple元组
- 看python官方说明学python-set-集合
- 看python官方说明学python-dict-字典
- 看python官方说明学python-list-列表
- 看python官方说明学python-class-object-类、对象-之区域和名空间
- 想学Python的朋友看这里
- 看python和莫名其妙学做网页。。。。
- 看代码学编程之python数据类型
- python天书-看代码学python(一)
- Python官方
- python中eval()函数官方文档的说明
- 学python
- 看代码学编程之python字符串格式化
- python 两个序列随机移位
- Caesar_Ciphers(凯撒移位)python描述
- python中移位操作 问题
- python如何看模块说明的,查模块位置
- Android模拟器上网
- How to fetch CRLs from distribution points
- C++编写安全OCX,IE不弹出安全提示框
- BM字符串匹配算法
- Sudoku
- 看python官方说明学python-移位-bitewise
- 在Linux下编译Google leveldb数据库及在C++中操作示例
- AT&T 汇编控制执行流程及与高级语言的转换
- CRL Distribution Point
- 7 Linux 文件与目录管理
- exec '/system/bin/sh' failed: Exec format error (8)... 错误解决
- OAuth
- 用例图、类图、活动图、类图和顺序图用法总结
- hashtable