Anomaly using a for loop to read bit values from byte array elements.

I seem to have come across an anomaly when reading the bit pattern within the elements of a byte array.
Specifically when I read the bits of the elements in the array using a “for loop”, the bit values
for the last element differ from the assigned values verified by other means. Certainly the MSB of
the last element seems to be affected by the anomaly.

When an extra element is declared in the array but not used, the readings for the bit values
(using the for loop), from the now pen-ultimate element read correctly.
Is this my bad or is there a rabbit away somewhere?

I include code showing a simple example.
Output is self explanatory.

BitAnomaly.txt (2.72 KB)

Please post your code here rather than attaching it and use code tags when you do.

Have you read the sticky posts at the top of the page with advice about how to use this forum and post a programming question ?

  byte xBuff[5];

xBuff is an array of 5 elements numbered 0 to 4

  xBuff[5] = B10000000;

Whoops !

byte xBuff[5];
  xBuff[1]=B10100111;
  xBuff[2]=B10000000;
  xBuff[3]=B00001010;
  xBuff[4]=B00000010;
  xBuff[5]=B10000000;

Oops

Well guys, That was extremely embarrassing. I'm surprised I got anywhere at all. Thank you for your comments. Kind Regards Dave Paxton