我没有像现在这样面临两难行动的问题:
Generate mask indicating leftmost 1 in x. Assume w=32.
For example, 0xFF00 -> 0x8000, and 0x6600 -> 0x4000.
If x = 0, then return 0.
The question also sets the limits that only using bitwise operations and "-" "+" to solve the problem. Here s detail:
隐蔽
Conditionals (if or ?:), loops, switch statements, function calls, and macro invocations. Division, modulus, and multiplication. Relative comparison operators (<, >, <=, and >=).
允许的行动
All bit-level and logic operations. Left and right shifts, but only with shift amounts between 0 and w – 1. Addition and subtraction. Equality (==) and inequality (!=) tests. (Some of the problems do not allow these.) Integer constants INT_MIN and INT_MAX. Casting between data types int and unsigned, either explicitly or implicitly.”
我可以理解这些问题的解决办法。 但是,我第一次没有接触过。 这是否意味着我缺乏任何知识,例如离散的数学? 是否有任何来源来开展高效的双向行动?