In anticipation of the thread being split, Ed has a comment.
> I suggest using a bitwise AND (much quicker as it doesn't involve a division)
This is a common misconception. Every time Edward tries to confirm such claims, the result is that the two are competitive at all optimization levels. While bitwise AND *is* statistically faster when averaging large numbers of tests, the actual difference in each test is vanishingly small.
Ed's conclusion is that it doesn't matter and you should pick whichever option is clearer. :)
>>you should start a new thread rather than reply to this one
>>in anticipation of the thread being split
FWIW: I agree with Ed. Optimizing on this level often leads to unreadable (/unmaintainable) code. When programming for something as powerful as a normal PC/Notebook, readability is preferred to micro-optimization.
I also do number << 1 and number >> 1 to multiply and divide by 2 ^^
(I come from a Games Programming and Embedded Devices background)
I have to agree with Nick, Ed et al; I guess your background explains it.
In general the performance difference is so minute that unless you're running some tiny embedded processor or doing a few billion of them, the clarity and readability of your code is way more important.
BTW, have we hijacked again by wandering off-topic?
vsawant: You'll need a way to tell even from odd (use if (number % 2 == 0) as already mentioned), a "for" loop to get from 1 to 100, and a way to print your results, probably "cout".
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
Hi, as I was told that my code doesn’t scale well at all, I thought perhaps I’d try to get a better understanding of interfaces/abstract classes and classes and the relationship between them.
I don’t want at this stage work on a big separate project as I've already got plenty ...