I'm trying to analyze some old code to understand what is it doing in case of error. This is the function:
error = -11;
protected String decodeError(int error){
StringBuffer msg = new StringBuffer();
for(int j=1; j<ERR_16+1; j=j*2 ){
if( (error&j)==j ){
switch(j){
case ERR_1:
msg.append("error1");
break;
case ERR_4:
msg.append("error4");
break;
case ERR_8:
msg.append("error8");
break;
case ERR_16:
msg.append("error16");
break;
}
}
}
return msg.toString();
}
ERR_16 = 16;
ERR_2 = 2;
ERR_4 = 4;
...
In case of error=-11, the function returns ERR_4. I know that & operator is bitwise AND operator but why someone should use it in this case?