解析Python中的二进制位运算符
2015-05-13 12:16
656 查看
下表列出了所有的Python语言的支持位运算符。假设变量a持有60和变量b持有13,则:
示例:
试试下面的例子就明白了所有的Python编程语言提供了位运算符:
#!/usr/bin/python a = 60 # 60 = 0011 1100 b = 13 # 13 = 0000 1101 c = 0 c = a & b; # 12 = 0000 1100 print "Line 1 - Value of c is ", c c = a | b; # 61 = 0011 1101 print "Line 2 - Value of c is ", c c = a ^ b; # 49 = 0011 0001 print "Line 3 - Value of c is ", c c = ~a; # -61 = 1100 0011 print "Line 4 - Value of c is ", c c = a << 2; # 240 = 1111 0000 print "Line 5 - Value of c is ", c c = a >> 2; # 15 = 0000 1111 print "Line 6 - Value of c is ", c
当执行上面的程序它会产生以下结果:
Line 1 - Value of c is 12 Line 2 - Value of c is 61 Line 3 - Value of c is 49 Line 4 - Value of c is -61 Line 5 - Value of c is 240 Line 6 - Value of c is 15
您可能感兴趣的文章:
相关文章推荐
- 解析Python中的二进制位运算符
- python二进制解析strut.upack的错误unpack requires a string argument of length 4
- python基于protobu+websocket+tornado实现多种二进制协议消息的接收发送和解析demo
- Python使用struct处理二进制 解析二进制数据 解析socket数据
- python二进制解析strut.upack的错误unpack requires a string argument of length 4
- 解析数值二进制位的python工具
- 二进制文件处理 WAV文件格式解析【利用python 将wav文件音量变小】
- 发现python的 位运算符 | 和 and 结果和竟然一样。
- Python位运算符
- Python命令行解析库argparse
- Python实现同域名下多个IP地址的解析
- 初步认识Python中的列表与位运算符
- Python下的数据处理和机器学习,对数据在线及本地获取、解析、预处理和训练、预测、交叉验证、可视化
- python http请求post参数,json解析
- android4.0 升级中python脚本解析ota_from_target_files<一>
- Python使用struct模块转换C语言结构体,打包、解包二进制数据
- Python 解析 xml文档
- python Kmeans算法解析
- python_xml文件的解析与构建