Finding if a number is a power of 2

前端 未结 7 1158
孤城傲影
孤城傲影 2021-02-18 18:15

Just out of curiosity, how can you tell if a number x is a power of two (x = 2^n) without using recursion.

Thanks

7条回答
  •  不知归路
    2021-02-18 18:39

    In a binary equivalent of any decimal number which is a power of two will have only one occurrence of 1 in its binary equivalent.

    
    

提交回复
热议问题