# [Tutor] Bitwise &

Robert Nanney nanney.56 at gmail.com
Wed Oct 14 19:37:35 EDT 2015

```To elaborate a little more this is comparing the 'one' bit. Any odd number
will have the 'one' bit set.
On Oct 14, 2015 6:30 PM, "Joel Goldstick" <joel.goldstick at gmail.com> wrote:

> On Wed, Oct 14, 2015 at 4:47 PM, ਨਿਹੰਗ ਪੰਜਾਬੀ <niihung at gmail.com> wrote:
>
> >  'if (n & 1)'  below works but I don't understand why/how.  Kindly help.
> >
> > ==============
> > >>> def fn(n):
> > ...     if (n & 1):
> > ...         print "n is odd"
> > ...     else:
> > ...         print "n is even"
> > ...
> > >>> fn(5)
> > n is odd
> > >>> fn(4)
> > n is even
> >
> > ===============
> >
>
> & is a bitwise operator, so any odd number and 1 will be one (true), and
> any even number will be zero (false)
> Any
>
> >
> > Thanks
> > Ni
> > _______________________________________________
> > Tutor maillist  -  Tutor at python.org
> > To unsubscribe or change subscription options:
> > https://mail.python.org/mailman/listinfo/tutor
> >
>
>
>
> --
> Joel Goldstick
> http://joelgoldstick.com/stats/birthdays
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> https://mail.python.org/mailman/listinfo/tutor
>
```