/* 用加法模拟乘法 */ #include <stdio.h> #include <stdlib.h> //#define T(O,R,N,i) (N&(1<<i)) && (O+=(R<<i)) #define T(o,a,b,i) (b&1<<i) && (o+=a<<i) int simulateMutiply(int a,int b) { int out=0; T(out, a, b, 0); T(out, a, b, 1); T(out, a, b, 2); T(out, a, b, 3); T(out, a, b, 4); T(out, a, b, 5); T(out, a, b, 6); T(out, a, b, 7); T(out, a, b, 8); T(out, a, b, 9); T(out, a, b, 10); T(out, a, b, 11); T(out, a, b, 12); T(out, a, b, 13); T(out, a, b, 14); T(out, a, b, 15); T(out, a, b, 16); T(out, a, b, 17); T(out, a, b, 18); T(out, a, b, 19); T(out, a, b, 20); T(out, a, b, 21); T(out, a, b, 22); T(out, a, b, 23); T(out, a, b, 24); T(out, a, b, 25); T(out, a, b, 26); T(out, a, b, 27); T(out, a, b, 28); T(out, a, b, 29); T(out, a, b, 30); T(out, a, b, 31); return out; } int main(void) { printf("%d \n",simulateMutiply(26,3)); return EXIT_SUCCESS; }
转自:http://blog.csdn.net/shandianling/article/details/8785481
本文转自夏雪冬日博客园博客,原文链接:http://www.cnblogs.com/heyonggang/p/3171557.html,如需转载请自行联系原作者