4 ms·
mod(x,2) will tell you that it's even, not that it's a power of two.
by nevinera 16y ago
mod(x,2) will tell you that it's even, not that it's a power of two.
- mfukar 16y agoLazy programmer it is!
- Retric 16y agoI think his first example was a recursive function like: if !(mod(x,2) { if (x == 1) return true else return false; }else return is_power_of_2(x/2); or if !(mod(x,2) { if (x == 1) return true; if ((x > 1) || (x == 0)) return false; return is_power_of_2(x * 2); }else if (x > 2) return is_power_of_2(x/2) else return false; PS: 2^0 = 1 and 2^-1 so you could have 3 versions of this fuction.