研发埠

标题: [google面试题]How 
can 
you 
quickly 
determine
 whether
 a 
number 
is 
a
 power
 of 
2? [打印本页]

作者: 邓英超    时间: 2013-7-30 15:43
标题: [google面试题]How 
can 
you 
quickly 
determine
 whether
 a 
number 
is 
a
 power
 of 
2?

作者: 亮    时间: 2013-7-30 16:14
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.




欢迎光临 研发埠 (http://bbs.yanfabu.com/) Powered by Discuz! X3.2