Comment on I wish

<- View Parent
Acters@lemmy.world ⁨1⁩ ⁨year⁩ ago

Every bit aside for the ones bit is even, all you have to do is yet the ones bit(the far left) for it being a 1 or 0. Which is the fastest and least amount of code needed.

use bitwise &
bool isEven(int n)
{

// n&amp;1 is true, then odd, or !n&amp;1 is true for even  

return (!(n &amp; 1));  

}

source
Sort:hotnewtop