思想:根据乘数每位上的值是否为1,是1的话则让res+该位对应倍数的y
class Sloution {
/*
* 求的是 x*y
* */
public int myMul(int x,int y){
int res = 0;
int i = 0;
boolean isNeg = (x*y)<0;
x = Math.abs(x);
y = Math.abs(y);
while(x!=0){//根据乘数每位上的值是否为1,是1的话则让res+该位对应倍数的y
if((x&1)!=0){
res+=(y<<i);
}
i++;
x = x>>1;
}
return (isNeg)?-1*res:res;
}
}