You're viewing a comment by Peter Kankowski and its responses.

October 30, 2009, 01:16

> Bit Hack #6. Turn off the rightmost 1-bit
This can be used to test if the number is a power of 2 (or zero):

if((x & (x-1)) == 0) // x is a power of 2

You should read bithacks page and Hacker's Delight book by Henry Warren, Jr. Both contain a lot of more complex bit tricks.

Reply To This Comment

(why do I need your e-mail?)

(Your twitter handle, if you have one.)

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

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