I was just thinking, and it might be wrong...but the difference of just 1 bit between two states is actually 2 to the power of the position which is different.
The thing I haven't proven is that the sum of the other positions that are different in case there's more than one, is never a perfect power of 2... now is that true? don't know for sure yet....
The thing is that it would mean calculating the decimal equivalent of the word bits, don't know if that works for you either.... And also it would mean calculating all differences between 2^N words... looong algorithm
Otherwise, a very basic soloution is simply looking at them as arrays and comparing, but it's some imbricated "for"'s u need...
I'll be thinking some more
Regards,
Tzushky
Added after 5 minutes:
I'm wrong... forget that ( if you have N=3 and look between level 2 and 1, 011 and 100 you get decimal difference 1 and Hamming distance 3, what I said is completely dumb, should have never wrote it....)
I don't see anything except treating them as arrays..., couting the elements that are different, when larger than one transition is 0, when equal to 1 transition is 1... It's just a lot of comparing..
and how do you generate the levels? The binary words?