Looks like you should just change this code:
if (temp & (1<<j)) row_buffer[8-j] |= 1<<(8-i);
else row_buffer[8-j] &= ~(1<<(8-i));
Perhaps this is just an assumption:
if (temp & (1<<j)) row_buffer[6-j] |= 1<<(7-i);
else row_buffer[6-j] &= ~(1<<(7-i));
8 - 6 8-7 . , , , , , , , , , .