I have the following if function that has a condition on an array of a data buffer, which stores data of a wav file
bool BFoundEnd = FALSE;
if (UCBuffer[ICount] != 0xFF){
BFoundEnd = TRUE;
break;
}
I was just confused on how 0xFF defines the condition inside the if function.
CodePudding user response:
what does variable != 0xFF mean in C ?
variable
is presumably an identifier that names a variable.
!=
is the inequality operator. It results in false when left and right hand operands are equal and true otherwise.
0xFF
is an integer literal. The 0x
prefix means that the literal uses hexadecimal system (base 16). The value is 255 in decimal system (base 10) and 1111'1111 in binary system (base 2). For more information about the base i.e. the radix of numeral systems, see wikipedia: Radix
CodePudding user response:
Reread with comments:
// Remembers if buffer did end with 0xFF (255) or not.
bool BFoundEnd = FALSE;
// ... Later in loop.
// Actual check for above variable
// (where "if ... != ..." means if not equal).
if (UCBuffer[ICount] != 0xFF) {
BFoundEnd = TRUE;
// Cancels looping as reached buffer-end.
break;
}
// ... Outside the loop.
// Handles something based on variable.
In short, someone decided to make
255
a special value which marks the end of the buffer and/or array (instead of providing array length).