1 bit-manipulation bit-shift go
当我执行j <<= 1while时j最初为零时,它最终为零,而不是通常应该为1.任何其他初始值通常加倍.
有谁知道为什么会这样?
为什么切片字段上的按位操作会导致运行时错误?
考虑j = 0:
0000 0000 0000 0000
Run Code Online (Sandbox Code Playgroud)
现在是什么j <<= 1?它的:
0000 0000 0000 0000
? ?
Shifted Added
Run Code Online (Sandbox Code Playgroud)
哪个是......相同的数字(0).
左移数字1,将其乘以2,0*2为0.