samyk/opensesame

Hmmm... something fishy here

GMDII opened this issue · 1 comments

GMDII commented

What in the world is this function doing?

"val ?" what is this... doesn't this need to be set? ":" instead of ";" ?

void setBit(u8 *A, u16 b, __bit val)
{
val ?
(A[b / 8] |= 1 << (b % 8)) :
(A[b / 8] &= ~(1 << (b % 8)));
}

? is an "if" operation, the ":" separates do this if true and do that if false. That is correct the way it is, it can be also written as.

void setBit(u8 *A, u16 b, __bit val){
  if(val==1){
    (A[b / 8] |= 1 << (b % 8));
  }
  else{
    (A[b / 8] &= ~(1 << (b % 8)));
  }
}

or you can put in it 1 line

val ? (A[b / 8] |= 1 << (b % 8)) : (A[b / 8] &= ~(1 << (b % 8)));

I can explain what this does but only while reading over https://www.tutorialspoint.com/cprogramming/c_operators.htm if I close that site I am lost again. Don't like clicking links? Google something like "C - Operators" or "C Bitwise Operators".