Explanation of shift operationals use in condition

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
}

Leave a Comment