On Jun 22, 4:07�pm, Ken Starks <stra...@lampsacos.demon.co.ukwrote:
weheh wrote:
I don't know if you found this example:
http://www.daniweb.com/code/snippet285.html
Thanks for that. The offerings are very similar to the
algorithms I wrote myself.
It wasn't the solution I was after,really; that's
easy. It was whether anything had found its way into
the standard library.
Isn't that coming in Python 3.0?
You could also use gmpy, which has a lot of
other bit-functionality in addition to displaying
them.
>>for i in xrange(8):
print 'i:',gmpy.digits(i,2).zfill(8),
print '# of 1-bits:',gmpy.popcount(i),
print 'find LS 1-bit:',gmpy.scan1(i),
print 'bit difference:',gmpy.hamdist(i,2**8-1)
i: 00000000 # of 1-bits: 0 find LS 1-bit: -1 bit difference: 8
i: 00000001 # of 1-bits: 1 find LS 1-bit: 0 bit difference: 7
i: 00000010 # of 1-bits: 1 find LS 1-bit: 1 bit difference: 7
i: 00000011 # of 1-bits: 2 find LS 1-bit: 0 bit difference: 6
i: 00000100 # of 1-bits: 1 find LS 1-bit: 2 bit difference: 7
i: 00000101 # of 1-bits: 2 find LS 1-bit: 0 bit difference: 6
i: 00000110 # of 1-bits: 2 find LS 1-bit: 1 bit difference: 6
i: 00000111 # of 1-bits: 3 find LS 1-bit: 0 bit difference: 5