Checking two arrays for equality.

Hi.
I have two arrays:

// Keep the current matrix setup.
unsigned char buffer[8] = { B00000000,
                            B00011100,
                            B00110100,
                            B00010000,
                            B00110110,
                            B00000010,
                            B00010100,
                            B00011100
                          };

// Keep the next life cycle.
unsigned char buffer2[8] = {B00001000,
                            B00110100,
                            B00100100,
                            B00000110,
                            B00111110,
                            B00110010,
                            B00010110,
                            B00010100
                          };

I need to check if they hold the same variables in each position (if they are equal).
My code for doing so is like this:

boolean isSame(){
  for(int i = 0; i < 8; i++){
    if(!buffer[i] == buffer2[i]){
      return false;
    }
  }
   return true;
}

But sometimes it gives false results.

The arrays that I give as an example return true. They should return false.

I am not sure what is going on here.
Maybe I have been working for too long.

Can someone spot what I am doing wrong or provide me with another way of checking for equallity?

Thanks.

Try:

if( ! (buffer[i] == buffer2[i]) ) {

Or better:

    if (buffer[i] != buffer2[i]) {

This is all due to what is called the "order of precidence" - i.e., the order in which terms get evaluated.

if(!buffer == buffer2*)*
That doesn't do what you think it does. You are thinking it gives "If not (these two terms being equal)". Instead it gives "If (not this term) equal to that term".
The ! goes with the buffer and is calculated first before comparing it to buffer2*.*
Either use brackets to group things as they should be or use != to mean "not equal".

Omg.
You are all right.

Thanks everyone, that is exactly what I oversaw. :confused:

I think you can use the command memcmp, it is one line command :wink:

See more info at http://www.cplusplus.com/reference/cstring/memcmp/

An example

if (memcmp(codeA, codeB, ArraySize) == 0) { //if it is the same then 
           //do something 
        }