【发布时间】:2015-02-04 04:56:49
【问题描述】:
似乎无法弄清楚“
11<< 2 is 44
1<<1 is 2
10<<2 is 40
【问题讨论】:
标签: math operator-keyword computation
似乎无法弄清楚“
11<< 2 is 44
1<<1 is 2
10<<2 is 40
【问题讨论】:
标签: math operator-keyword computation
移位运算符,将其左侧的值按其右侧的位数按位移动:
>> 右移,如果 value 是无符号类型,则添加 0;如果 value 是有符号类型,则扩展最高位(以保留符号)。
因此,2 > 3 是 -1。
参考: http://www-numi.fnal.gov/offline_software/srt_public_context/WebDocs/Companion/cxx_crib/shift.html
【讨论】:
这在计算中被称为位移。
11 => 1011 因此,如果您将左移为 11
举例说明
如果对 1011 应用 00
所以如果你检查 101100 的十进制值, 1*(32) + 0*(16) + 1*(8) + 1*(4) + 0*(2) + 0*(1) = 44
短方法
11
1
10
a
【讨论】: