[google面试题]How can you quickly determine whether a number is a power of 2?
Good answer:Check whether x &(x‐1) is 0.If x is not an even power of 2,thehighest position of x with a1 will also have a1 inx‐1;otherwise,x will be100...0and x‐1 will be 011...1;and’ing them together will return 0.
页:
[1]