Is there an algorithm or a mathematical function which has the same result as the below method?
For 0 return 0
For 1...15 return 1
For 16...255 return 2
For 256...n return value doesn't matter, any number would be valid
I especially look for a one line function which can be assigned to a variable or used as a parameter. All the solutions I can think of contain more than one line or failed mathmatically (bit shifting, binary operations etc) ... For my friend jeb a multiline version of the algorithm:
public int function(int anyInt){
if(anyInt>15){
return 2;
}
else if(anyInt>0){
return 1;
}
else{ //anyInt==0 or smaller
return 0;
}
}
Update: Integer (calculation) based solutions are prefered.