John <ia******@hotmail.com> wrote:
I came across this nugget in my intarweb travels. It's part of a
median-calculation. Can someone tell me what the if( length & 0x1 ) is
doing?
Thanks!
---------------------------------------------
/* Is vector length odd or even ? */
if (length & 0x1)
ans = pCopy[length/2];
else
ans = .5 * (pCopy[length/2 - 1] + pCopy[length/2]);
Well it's the same as (lenght & 1) which will be true when
the least significant bit of the value of length is set. That
means the value in length is odd.
Did you read the comment above the code?
--
Z (Zo**********@daimlerchrysler.com)
"LISP is worth learning for the profound enlightenment experience
you will have when you finally get it; that experience will make you
a better programmer for the rest of your days." -- Eric S. Raymond