码迷,mamicode.com
首页 > 编程语言 > 详细

python学习笔记(3)—— 进制

时间:2014-11-20 18:40:00      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:style   blog   color   使用   sp   on   div   log   bs   

  python中使用二进制也很方便

  1、表示

1 one = 0b1
2 two = 0b10
3 three = 0b11

  2、操作

1 print 5 >> 4  # Right Shift
2 print 5 << 1  # Left Shift
3 print 8 & 5   # Bitwise AND
4 print 9 | 4   # Bitwise OR
5 print 12 ^ 42 # Bitwise XOR
6 print ~88     # Bitwise NOT

  3、转换

1 print int("0b100",2)
2 print int(bin(5),2)
3 print int("11001001",2)
1 print bin(1)
2 print bin(2)
3 print bin(3)

 

python学习笔记(3)—— 进制

标签:style   blog   color   使用   sp   on   div   log   bs   

原文地址:http://www.cnblogs.com/andrew-elec90/p/4111160.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!