We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
You do if (a % 2 == 0) I disagree in 2 ways:
1) a isn't a good variable name.
2) modulo is slower than & (aka bitand)
if (number & 1 != 0) number is odd. It's binary representation ends in 1.
Of course this, afaik, only works with 2's complement numbers (for negative nums) which is only standard in every single cpu available in the last 40 years.
Who knows… Maybe IBM will release another sign magnitude cpu and when it doesn't sell you can keep on using my technique. ._.
For Loop
You are viewing a single comment's thread. Return to all comments →
You do
if (a % 2 == 0)
I disagree in 2 ways: 1)a
isn't a good variable name. 2) modulo is slower than&
(akabitand
)if (number & 1 != 0)
number is odd. It's binary representation ends in 1. Of course this, afaik, only works with 2's complement numbers (for negative nums) which is only standard in every single cpu available in the last 40 years.Who knows… Maybe IBM will release another sign magnitude cpu and when it doesn't sell you can keep on using my technique. ._.