You're viewing a comment by hydraurlz and its responses.

July 01, 2009, 15:58

check if a number is power of 2

if ( ( n && ( n-1 ) ) == 0 )
{
//power of 2
}
else
{
//not power of 2
}

Comment Responses

Tom Kha Gai Permalink
October 20, 2010, 16:40

FIX: && => &

Additionally: can also be written as

(n & (-n)) == n

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

Type the word "unix_143": (just to make sure you're a human)

Please preview the comment before submitting to make sure it's OK.