This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Compiler/MSP430F1611: Bitwise invert and if expression

Part Number: MSP430F1611

Tool/software: TI C/C++ Compiler

Hello,

I have a question due to some weird issues compiling code.

int test(char * header) {
  if (header[0] == ~header[1]) {
    return 0;
  }
  return 1;
}

This code does not work. It does not return 0, if the second byte is the bitwise invertation of the first byte. But the following code DOES work:

int test(char * header) {
  char test[2];
  test[0] = header[0];
  test[1] = ~header[1];
  if (test[0] == test[1]) {
    return 0;
  }
  return 1;
}

Can someone explain me why this is happening?

**Attention** This is a public forum