這是
Note that the plot that was previously here was wrong! The code and data were not though. The code has been updated to include @MarkRansom's solution, since it turns out to be the optimal solution for very large numbers (over 4k-bit numbers).
uj5u.com熱心網友回復:
while (num & 0xffffffff) == 0:
num >>= 32
if (num & 0xffff) == 0:
num >>= 16
if (num & 0xff) == 0:
num >>= 8
if (num & 0xf) == 0:
num >>= 4
if (num & 0x3) == 0:
num >>= 2
if (num & 0x1) == 0:
num >>= 1
這里的想法是執行盡可能少的班次。初始while回圈處理超過 32 位長的數字,我認為這不太可能,但必須提供它以確保完整性。之后,每條陳述句移動一半的位;如果你不能移動 16,那么你最多可以移動 15,即 (8 4 2 1)。if這 5 個陳述涵蓋了所有可能的情況。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/447850.html
上一篇:打開鍵盤時如何防止小部件重建
下一篇:宣告期間呼叫的查找映射函式
