Hi Please somebody can explain me the meaning of this conditional statement? This is a java code.
(chaIntVal >= 0x10 ? chaIntVal : chaIntVal | 0x60)
Hi Please somebody can explain me the meaning of this conditional statement? This is a java code.
(chaIntVal >= 0x10 ? chaIntVal : chaIntVal | 0x60)
It means:
int res;
if(chaIntVal >= 0x10) {
res = chaIntVal;
} else {
res = chaIntVal | 0x60; // binary or
}
It is a ternary operator which means this.
condition ? value_if_true : value_if_false;
It is almost equivalent to
if(condition){
// when true do this
}else{
// when false do this
}
This expression returns chaIntVal as is if chaIntVal > 16; otherwise it will set bits 5 and 6 to 1 of chaIntVal (binary OR http://www.xcprod.com/titan/XCSB-DOC/binary_or.html) and returns it.
If the high bits after the 4 low bits of the value are not set (value in range 0-15), do set bits x11x xxxx.