I need to write a function that calculates the database floor 16 of an unsigned int passed to. There are restrictions as to which operators and which constants we are allowed to use, and we can only use for tags,
For clarity, we cannot use any conditional statements (if, else, switch ...). Function Prototype:
int floor_log16(unsigned int x);
Valid operators: ++ -- = & | ~ ^ << ! >>
Permitted constants: 1 2 3 4 8 16
I wrote the version of the program as follows:
int floor_log16(unsigned int x) { int index=1; int count=(1!=1); count--; for(; index<=x; index<<=4) { count++; } return count; }
which seems to work as desired. However, I realized that, based on later functions and a description of the necessary functionality, we should write, I noticed that under the "allowed operators" sometimes indicated > and < .
It follows that since the floor_log16 function mentioned above was not explicitly told to use > or < , I can only assume that the solution described above will not be accepted.
This leaves me rather confused because I don't understand how you can have a for loop without a logical check?
Isn't the whole idea of ​​the loop repeated until the condition is met?
source share