Re: Number of bits/sizeof int

2009-02-03 Thread Mark Dickinson
On Feb 3, 1:19 am, Mark Wooding wrote: > Yeah, I made some arbitrary choices about what to do with non-positive > inputs.  If you prefer other answers, use 'em.  My ones work well with > signed-magnitude representations where the sign is stored separately. Not *that* arbitrary: they're the same

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Wooding
John Machin writes: > 3 can be represented in 2 bits and at the same time -3 can be > represented in 2 bits?? But 2 bits can support only 2 ** 2 == 4 > different possibilities, and -3 .. 3 is 7 different integers. Yeah, I made some arbitrary choices about what to do with non-positive inputs. If

Re: Number of bits/sizeof int

2009-02-02 Thread casevh
On Jan 30, 11:03 pm, Jon Clements wrote: > Hi Group, > > This has a certain amount of irony (as this is what I'm pretty much > after):- > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its

Re: Number of bits/sizeof int

2009-02-02 Thread John Machin
On Feb 3, 6:50 am, Mark Wooding wrote: > Jon Clements writes: > > "The int() type gained a bit_length method that returns the number of > > bits necessary to represent its argument in binary:" > > > Any tips on how to get this in 2.5.2 as that's the production version > > I'm stuck with. > > def

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Dickinson
On Jan 31, 7:03 am, Jon Clements wrote: > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. It's a bit cheeky, but: from decimal import _nbits as nbits should also work in 2.5.2 (but not in 2.5.1)! Mark -- http://mail.python.org/mailman/listinfo/python-l

Re: Number of bits/sizeof int

2009-02-02 Thread Mark Wooding
Jon Clements writes: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its argument in binary:" > > Any tips on how to get this in 2.5.2 as that's the production version > I'm stuck with. def nbits(x): ## Special cases. if x == 0: return 0

Re: Number of bits/sizeof int

2009-01-30 Thread Jon Clements
On Jan 31, 7:29 am, John Machin wrote: > On Jan 31, 6:03 pm, Jon Clements wrote: > > > Hi Group, > > > This has a certain amount of irony (as this is what I'm pretty much > > after):- > > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > > "The int() type gained a bit_length method that ret

Re: Number of bits/sizeof int

2009-01-30 Thread Gabriel Genellina
En Sat, 31 Jan 2009 05:03:27 -0200, Jon Clements escribió: This has a certain amount of irony (as this is what I'm pretty much after):- From http://docs.python.org/dev/3.0/whatsnew/3.1.html: "The int() type gained a bit_length method that returns the number of bits necessary to represent it

Re: Number of bits/sizeof int

2009-01-30 Thread Scott David Daniels
Jon Clements wrote: ... From http://docs.python.org/dev/3.0/whatsnew/3.1.html: "The int() type gained a bit_length method that returns the number of bits necessary to represent its argument in binary:" Any tips on how to get this in 2.5.2 as that's the production version I'm stuck with. Well,

Re: Number of bits/sizeof int

2009-01-30 Thread John Machin
On Jan 31, 6:03 pm, Jon Clements wrote: > Hi Group, > > This has a certain amount of irony (as this is what I'm pretty much > after):- > Fromhttp://docs.python.org/dev/3.0/whatsnew/3.1.html: > "The int() type gained a bit_length method that returns the number of > bits necessary to represent its a