【问题标题】:Why is 1<<3 + 1<<4 = 256?为什么 1<<3 + 1<<4 = 256?
【发布时间】:2021-01-09 16:58:02
【问题描述】:

我以为它会等于 1

python interpreter

【问题讨论】:

标签: python binary bit-manipulation bit boolean-algebra


【解决方案1】:

这是因为 python 的操作顺序,在左移运算符之前计算加法。表达式等价于

(1<<(3+1))<<4

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-11-03
    • 1970-01-01
    • 2015-04-07
    • 1970-01-01
    • 2010-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多