i did my best to do this function, the following is what i came up with.
However, the max operators that i can use is 12 and i'm using 16. i did all i
can to have the min number of operatores and the min was 16 .Please Help!
/ * multFiveEight - multiplies by 5/8 rounding toward 0.
* Examples: multFiveEights(77) = 48
* multFiveEights(-22) = -13
* You can assume |x| < (1 << 29)
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 12
* Rating: 3
*/
Code:int multFiveEight(int x) { int negMask=1<<31; int pos=!(x&negMask); int ones=~0; int y=(x<<2)+x; int y_neg=(~(y>>4))+1; int y_pos=y>>3; return ((ones+pos)&y_neg)|((ones+!pos)&y_pos); }