01-20-2014 12:45 PM
01-20-2014 02:46 PM
01-20-2014 04:07 PM
@jcarmody wrote:
I love it when a homework question (d)evolves into something like this. 😄
We can only hope the OP tunes in and learns something new.
@ Altenbach: Sooo, the LSB of the binary representation of number is like the result of an isOdd() function. Completely obvious but I never thought of it that way.
01-21-2014 02:02 AM - edited 01-21-2014 02:02 AM
Honestly, i disregarded performance (speed and memory wise) consciously because he might have the task to develop code which does not determine even or odd, but maybe something with more options.
Therefore, the hint to Q&R is imho essential as it is a very powerful, but simple to use option for numeric "evaluations".
Norbert
EDIT: But i do like the discussions about performance and better (advanced) options to squeeze the last bit and byte out of a computer system!
01-21-2014 02:21 AM
@Norbert. I saw your edit and agree. This sort of task certainly tickles the little grey cells.
With that in mind here is another contender ... not quite as fast as the AND, but not too shabby.
01-21-2014 03:22 AM
Well, you are taking a 32 bit integer, coverting it to an 8 bit integer, then to a 8x larger (in memory) boolean array, then throwing 7/8 of the information away, retaining only 1/8 of the data. That seems lik a lot of unecessary data manipulation. 😄
(It is possible that the compiler can streamline some of this under the hood, but that does not make it right).
01-21-2014 04:59 AM
... just trying a few ideas and seeing what LV makes of 'em.
"(It is possible that the compiler can streamline some of this under the hood, but that does not make it right)."
I don't see any broken lines so where is the wrong bit ?