[Tutor] Finding even and odd numbers

taserian taserian at gmail.com
Wed Sep 19 17:28:33 CEST 2007

> > The above snippet is taking advantage of a similar property of binary
> > numbers, which are base 2. What the above snippet is doing is checking
> to
> > see if that last digit is a 0 or not (asking "not n&1" is equivalent to
> > asking "n&0", since that digit can only be a 0 or 1).
> Not quite.  The &1 is simply checking the least significant bit in the
> word.  n&0 will always give 0.  not n&1 checks whether the last digit
> -is- or -isn't- 1.
> S.

Not at all, you mean. I was way off with that statement; I'll plead not
guilty by virtue of not having had enough coffee today.

<8-(  (Wearing the dunce cap. . .)

Tony R.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20070919/d58ef525/attachment-0001.htm 

More information about the Tutor mailing list