at first i wanted to say that this programmer never had
to deal with 16 bit ints. but charmingly, it even works for 16 bit ints.
(because the 1<<16 == 0, and -1 == 0xFFFF).

On Oct 8, 2010, at 10:27 AM, Tom Limoncelli wrote:

I see this in code now and then:

                1<<16-1

Python and C interpret that as "1 << (16 - 1)", which is 32768.

The programmer usually means "(1 << 16) - 1", which is 65535.

There's a big difference, especially if you are using these for bit masks:

32768 = 1000000000000000
65535 = 1111111111111111

Tom
_______________________________________________
Tech mailing list
Tech@lopsa.org
http://lopsa.org/cgi-bin/mailman/listinfo/tech
This list provided by the League of Professional System Administrators
 http://lopsa.org/

------------------
Andrew Hume  (best -> Telework) +1 623-551-2845
and...@research.att.com  (Work) +1 none currently
AT&T Labs - Research; member of USENIX and LOPSA




_______________________________________________
Tech mailing list
Tech@lopsa.org
http://lopsa.org/cgi-bin/mailman/listinfo/tech
This list provided by the League of Professional System Administrators
 http://lopsa.org/

Reply via email to