Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定两个数字 a 和 b,其中 b 的形式为 2 k,其中 k 未知。使用按位运算符计算 a%b 的有效方法是什么。
a AND (b-1) == a%b(当 b 为 2^k 时)
ex. a = 11 (1011b), b = 4 (0100b) 11 / 4 = 2 R3 11 % 4 == 11 AND (4-1) 11 (1011b) AND 3 (0011b) == 3 (0011b)