Python  mask

11.bit mask
a bit mask can help you turn specific bits on,turn other off,or just collect data from a integer about which bits are on or off.

mask = 0b1000
the fourth bit from the right is on
mask =0b0100
third bit from the right is on

13.just flip out
want to flip all of the bits in a
a = 0b110
mask = 0b111
a 与 mask 的长度一样,只是mask 全是1

12.turn it on
want to make sure the rightmost bit of number a is turned on

a = 0b110

6

mask = 0b1

1

desired = a | mask

0b111,or 7

using the bitwise | operator will turn a corresponding bit on if it is off and leave it on if it is already on

the bitwise OR(|) operator compares two numbers on a bit level and returns a number where the bits of that number are turned on if either of the corresponding bits of either number are 1.

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 13,494评论 0 23
  • 父亲的脊背 林智宏 父亲的个子很高很瘦,脖子伸的老长,皮肤被烈日和风霜染成了古铜色,而且他脊背简直就是一张大弓。父...
    林智宏阅读 3,942评论 0 2
  • 小城往东 香樟树绿叶葱茏 小城往西 路旁菜农摆着摊位 走过南北 风中飘着些辣子味
    向冉阅读 1,189评论 3 5

友情链接更多精彩内容