Here's my code:
is this true? I tried it and it doesn't work as it's supposed to be. So is there another easier way?Code:((num & (num - 1)) == 0)
Printable View
Here's my code:
is this true? I tried it and it doesn't work as it's supposed to be. So is there another easier way?Code:((num & (num - 1)) == 0)
Check if the square root is a whole number.
It should work. What numbers are you using?
--
Mats
I am trying to use 3
oh nvm.. I found my self a stupid little mistake :D
Power of two means two raised to a power, not a number raised to the second power. It's 2^x not x^2.
edit: The reason that first equation works is that any power of a number will be 1000 in that number system. 10, 100, 1000 are all powers of ten in the base-ten system. In base-two, they are all powers of two. Subtract one, and there will be a one in place of all the zeroes. 100 - 1 = 011. 100 & 011 = 0.