unsigned int \ long

Michael Peuser mpeuser at web.de
Wed Aug 13 07:07:19 EDT 2003


Hi Roman,

> "Roman Yakovenko" <romany at actimize.com> schrieb im Newsbeitrag
news:mailman.1060766064.21827.pythonlist at python.org...

> 1. Bitwise operations
>  ~210 | 118 == -129

> I'd like to get 127 ( of course if I work within byte or smth like this ).

I think this is a misconception! It makes no sense to use ~X without being
aware of something like a "wordlength".
You should use (255^X) instead

> Today in order to get it I have to write ( ~210 | 118 ) & 0xFF

Well.....


> 2. Example
> def print_selection( some_list, range=(0,-1) ):
> lower = max( 0, range[0] )
> upper = min( len( some_list ), unsigned_int( range[1] ) )
> print some_list[lower:upper]

I should not consider it good style to interpret -1 as plus infinite...

Kindly
Michael P.







More information about the Python-list mailing list