Comments on: Next greater power of 2 https://demo.ritambhara.in/next-greater-power-of-2/ Coding / System Design Interviews Thu, 31 Jan 2013 04:25:38 +0000 hourly 1 https://wordpress.org/?v=6.7.2 By: Kamal Rawat https://demo.ritambhara.in/next-greater-power-of-2/#comment-1897 Thu, 31 Jan 2013 04:25:38 +0000 http://www.ritambhara.in/?p=288#comment-1897 In reply to Raj Chaudhary.

this will fail for n == 0.. the check of extra n is just for the case when n is zero.. because for n==0 (!(n&(n-1)) is true.. but zero is not a power of two..

]]>
By: Kamal Rawat https://demo.ritambhara.in/next-greater-power-of-2/#comment-1898 Thu, 31 Jan 2013 04:25:31 +0000 http://www.ritambhara.in/?p=288#comment-1898 In reply to Raj Chaudhary.

this will fail for n == 0.. the check of extra n is just for the case when n is zero.. because for n==0 (!(n&(n-1)) is true.. but zero is not a power of two..

]]>
By: Raj Chaudhary https://demo.ritambhara.in/next-greater-power-of-2/#comment-1896 Wed, 30 Jan 2013 17:05:33 +0000 http://www.ritambhara.in/?p=288#comment-1896 I thinks Instead of (n &&!(n & (n – 1))) if (!(n & (n – 1)) is sufficient.

]]>