与无符号长乘法对齐

时间:2013-04-13 06:47:41

标签: c

要掌握C(不是母语)中的乘法函数 - 必须使用按位运算符。非常困难,试图提出一个解决方案实现来取代return 0;

任何方向都非常感激:

unsigned long multiply(unsigned int x, unsigned int y) {
   return 0;
}

1 个答案:

答案 0 :(得分:2)

请参阅此链接了解bitwise operation

c := 0
while b ≠ 0
    if (b and 1) ≠ 0
        c := c + a
    left shift a by 1
    right shift b by 1 
return c

这应该对你有很多帮助,从这里开始。所有你需要做的就是将它转换为C.这对你来说是一个很好的做法。

提示:

左移a 1 a<<=1;

如果(b和1)≠0 可以写成:if (b&01)