[Tutor] Finding even and odd numbers
sanelson at gmail.com
Wed Sep 19 15:58:15 CEST 2007
On 9/19/07, Boykie Mackay <boykie.mackay at gmail.com> wrote:
> Hi guys,
> I have come across a bit of code to find if a group of numbers is odd or
> even.The code snippet is shown below:
> if not n&1:
> return false
> The above should return false for all even numbers,numbers being
> represented by n.I have tried to wrap my head around the 'not n&1' but
> I'm failing to understand what's going on.Could someone please explain
> the statement.
It's just a bitwise and, which will always return 1 for an odd number.
More information about the Tutor