On Mon, Jun 10 @ 09:41, Tim Peters wrote: > If you have a *positive* long that would fit in a 32-bit unsigned int (which > type Python doesn't have), and know you're running on a 32-bit box, and only > want the same bit pattern in an int, you can do > > def toint32(long): > if long & 0x80000000L: > long -= 1L << 32 > return int(long) > > This also raises OverflowError if you're mistaken about it fitting in 32 > bits. Whoops. That should have been a 0x8... in my example :) At ny rate, I wish this function was available as a built-in. It would be nice if I had some conversion function where python looked at the highest bit and treated that as my word boundary to determine whether the number is positive or not. -- Mike -- Michael Gilfix mgilfix@eecs.tufts.edu For my gpg public key: http://www.eecs.tufts.edu/~mgilfix/contact.html
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4