Re: Hamming Distance

2008-06-27 Thread Jared Grubb
res Law ] x * ( (X+y)*(x+Y) ) [ inversion] x * (X+y) * (x+Y) [ associative] (xX+xy)*(x+Y) [ distributive ] xy*(x+Y) [ xX = 0 ] xy+xyY [ distrib ] xy[yY = 0] So, x &= x-1 On 19 Jun 2008, at 17:37, Matimus wrote: On Jun 19, 4:27 pm, godavemon <[EMAIL PROTECTED]> wrote: I need to

Re: Hamming Distance

2008-06-27 Thread Hans Terlouw
godavemon wrote: I need to calculate the Hamming Distance of two integers. The hamming distance is the number of bits in two integers that don't match. ... What about letting the bits count themselves in a parallel adding scheme: def hamming(i, j): i ^= j i = ((i&044

Re: Hamming Distance

2008-06-19 Thread godavemon
Great thanks! On Jun 19, 5:37 pm, Matimus <[EMAIL PROTECTED]> wrote: > On Jun 19, 4:27 pm, godavemon <[EMAIL PROTECTED]> wrote: > > > > > I need to calculate the Hamming Distance of two integers. The hamming > > distance is the number of bits in two integ

Re: Hamming Distance

2008-06-19 Thread godavemon
Awesome! Thanks a lot. On Jun 19, 5:00 pm, Mensanator <[EMAIL PROTECTED]> wrote: > On Jun 19, 6:27 pm, godavemon <[EMAIL PROTECTED]> wrote: > > > > > I need to calculate the Hamming Distance of two integers. The hamming > > distance is the number of bits

Re: Hamming Distance

2008-06-19 Thread Raymond Hettinger
Non-recursive, 8-bit block table lookup version: def ham(a, b, ht=[hamdist(a,0) for a in range(256)]): x = a ^ b dist = 0 while x: dist += ht[x & 255] x >>= 8 return dist Raymond -- http://mail.python.org/mailman/listinfo/python-list

Re: Hamming Distance

2008-06-19 Thread Matimus
On Jun 19, 4:27 pm, godavemon <[EMAIL PROTECTED]> wrote: > I need to calculate the Hamming Distance of two integers.  The hamming > distance is the number of bits in two integers that don't match.  I > thought there'd be a function in math or scipy but i haven't bee

Re: Hamming Distance

2008-06-19 Thread Mensanator
On Jun 19, 6:27 pm, godavemon <[EMAIL PROTECTED]> wrote: > I need to calculate the Hamming Distance of two integers.  The hamming > distance is the number of bits in two integers that don't match.  I > thought there'd be a function in math or scipy but i haven't bee

Re: Hamming Distance

2008-06-19 Thread Robert Kern
godavemon wrote: I need to calculate the Hamming Distance of two integers. The hamming distance is the number of bits in two integers that don't match. I thought there'd be a function in math or scipy but i haven't been able to find one. This is my function but it seems like th

Re: Hamming Distance

2008-06-19 Thread John Machin
On Jun 20, 9:27 am, godavemon <[EMAIL PROTECTED]> wrote: > I need to calculate the Hamming Distance of two integers. The hamming > distance is the number of bits in two integers that don't match. I > thought there'd be a function in math or scipy but i haven't bee

Re: Hamming Distance

2008-06-19 Thread Raymond Hettinger
On Jun 19, 4:27 pm, godavemon <[EMAIL PROTECTED]> wrote: > I need to calculate the Hamming Distance of two integers.  The hamming > distance is the number of bits in two integers that don't match.  I > thought there'd be a function in math or scipy but i haven't bee

Hamming Distance

2008-06-19 Thread godavemon
I need to calculate the Hamming Distance of two integers. The hamming distance is the number of bits in two integers that don't match. I thought there'd be a function in math or scipy but i haven't been able to find one. This is my function but it seems like there should be a fa