-6

I have a c code given to me to fill for my thesis. Can you please explain what the following segment does, because i'm very buffled with it.

int i;
_int8 codeword[64800];

//loop running through codeword
if (codeword[i << 1] << 1 | codeword[i << 1 | 1])
    {
      //more code here
    }

where i is a loop counter and codeword[] is an 1d matrix of ones and zeros

I mostly seek explanation of the operations taking place if, for example, codeword[i] is 1.

1 Answers1

1

The test combines the 2 bits in codeword at offset 2 * i and 2 * i + 1 and evaluates the body if they are not both 0. The expression is parsed as:

int i;
_int8 codeword[64800];

//loop running through codeword
if ((codeword[i << 1] << 1) | codeword[(i << 1) | 1]) {
    // more code here
}

Note that the expression would be equivalent but more readable as:

int i;
_int8 codeword[64800];

//loop running through codeword
if (codeword[2 * i] || codeword[2 * i + 1]) {
    // more code here
}
chqrlie
  • 131,814
  • 10
  • 121
  • 189