Finding the bit/bits from one digit which different it from group of other digits (Kazakow method)

The method is generally called Kazakow and I'm looking for
C/C++ implementation or even help where to find it or how it may work

About the method:
We have one digit(F0) and a group of other digits(F1).



We want to find the bit/bits which different F0 and F1.
The result must contains the fewest bits which different them
so the answer is -1-- (bit 3) - only one bit in this exapamle !!

_generaly for ONE bit  

for i := 1 to n do {numbers of bits}
     { here I compare F0 and F1 }
        { by the bit number i }
_for TWO bit  

  for i := 1 to n-1 do
     for j :=i+1 to n do
     { here I compare F0 and F1 }
        { by the bit number "i" and bit "j"}
but how to find n-bits which different them ?!
this situations accurs in Karnaugh grid where '1' is
rounded with '0'

What for this example ?!


what if I have 20-bits digits ?!

I think that some sort of adding items or even recuration is here needed

Any suggestions ?

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

I'm not quite sure I understand the problem, but if you want to find the bits that differ in two words, all you have to do is:

a = 0010101110110101;
b = 0000010110111000;

c = a XOR b;

c is now:  
a = 0010101110110101;
b = 0000010110111000;
c = 0010111000001101;

'c' has all the bits that differ in a and b.

Now to find the number of bits that are different, you can do it two ways, slow and fast.

slow:  for( i=tot=0;i<WordWith;i++ ) tot += (c >> i) & 1;

This takes "WordWidth" loops.

If WordWidth is some reasonable number, like 16,
then you can use the slow method to precompute a table and just index into the table to look up the number of bits in c.

Hope this helps!

int Difference(int a, int b)
  int d = a ^ b; // XOR
  int c=0;
  while( d )
    c+= (d & 1);
    d = d >> 1;
 return c;

Same thing as what grg99 is saying but you don't need to know the widths.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:
Accept TheBeaver's comment
Please leave any comments here within the next seven days.


EE Cleanup Volunteer
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.