Iterating over an unsigned char array bit by bit.

Hi.
I am working with some LED matrices to try to make Game of Life and I am having a problem with my program. Currently I am only using a single matrix.
I have this array which I use to store the current state of the matrix in:

unsigned char buffer[8] = { B00000000,
                            B00000000,
                            B00101000,
                            B00000000,
                            B00010000,
                            B00000000,
                            B00000000,
                            B00000011
                          };

Now I want to iterate over each bit in the array from position 0,0 (upper left corner) down to 7,7 (lower right corner) bit by bit.
The reason I want to do this is because for every LED I have to check the neighbooring LEDs if they are on or off.

Does someone know a way to do this? I don't mind changing the structure of how I store the state of the matrix.

Thanks.

EDIT:
The ideal solution I was hoping for is something like this:

for(int i = 0; i < 8; i++) {
for(int y = 0; y < 8; y++){
bit currentBit = buffer[i][y];
// Here would be the logic where I check the bits around the currentBit.
// if(buffer[i-1][y] == 1) then something and so on....

}
}

You need two nested loops, one to iterate over the bytes in your array and another to iterate over the bits in each byte.

Or use mask and shift (or divide and modulo) operations to allow a single index to access both bytes and bits.

You are close...

bit currentBit = bitRead(buffer[i],y);

My BitBool library makes this easy.

BitBool< 64, true > buffer ={ B00000000,
                        B00000000,
                        B00101000,
                        B00000000,
                        B00010000,
                        B00000000,
                        B00000000,
                        B00000011
                      };
void setup() {
  Serial.begin( 9600 );
  
  for( char i = 0 ; i < buffer.BitCount ; ++i ){
    Serial.print( buffer[ i ], DEC );
  }  
}

void loop() {}

EDIT: Removed comment about pYro_65 code. It compiles.

DavidOConnor: That does not want to compile. It gives me:

LCDemoMatrixWorking.ino: In function 'void test()':
LCDemoMatrixWorking:242: error: 'bit' was not declared in this scope
LCDemoMatrixWorking:242: error: expected `;' before 'currentBit'

I guess I assumed you had typedef'ed bit. Use byte instead.

Thanks. The bitRead function did the trick.