Iterating through bits

Hello,

I'm trying to test a decoder that I have implemented in hardware.I need to iterate through the bits of a 16-bit word and invert them. Each inversion corresponds to a "bit error" of which there may be 1 - 16 bit errors.

i.e. for each word, invert one of the bits and test the new word. For 2-bit errors, invert the first bit and the second bit and the following ones after that. Then invert the second bit and third bit and then the following bits recursively etc. As the number of bit-errors increase the code gets more complex.

The only way I can see this working is if I use 16 For loops to keep track of where in the word I am and which n-bit error I am currently testing.

I am not looking specifically for code, but more a better way of doing the test.

Any help would be appreciated.
You could use a bit mask such as 0x0001. Then, XOR (^) it with your word to invert that bit, leaving all others untouched, and test it. Finally, bit shift (<<) the mask and repeat to test the next bit.
Topic archived. No new replies allowed.