-1

I came across this question and I couldn't find it in textbooks or the internet. Seems pretty unique.

I guess there would be some comparators and adders involved, but I have no clue where to start.

10 Rep
  • 2,217
  • 7
  • 19
  • 33
McGill
  • 49
  • 5
  • Not a programming question - try http://electronics.stackexchange.com ? – Paul R Oct 28 '16 at 08:03
  • 1
    The circuit has to count the number of bit positions where the two code words are different. Technically, this is a bit-wise exor of the two words combined with a counter circuit. The bit count is described in a [related post](http://stackoverflow.com/questions/3815165/how-to-implement-bitcount-using-only-bitwise-operators). It should be easy to map the described calculation to a circuit. – Axel Kemper Oct 28 '16 at 08:33
  • I'm voting to close this question as off-topic because it is about circuit design instead of programming or software development. – Pang Oct 29 '16 at 04:33

1 Answers1

1

The first step will undoubtedly be XORing the two bit sets. Then you need to count the number of logical ones in the output. The best method for designing your circuit would be to make a complete analogy of the hack discussed in this question and explained perfectly in its answer by nneonneo. This would result in the optimal tree of adders, rather than relying on sequential counting. The idea is that in each layer you know how to cap the maximum possible sum of a subset of the inputs, and in how many bits it will fit, eliminating the need for a carry bit. The programming approach is designed for 32 bits but easily modifiable for less or more than that.

For more possible algorithms for computing Hamming weight see this link.

Community
  • 1
  • 1
The Vee
  • 11,420
  • 5
  • 27
  • 60