标签:style blog io color os sp for div log
1 /* 2 二进制乘法 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 #define LEN 64 //因子二进制位数的两倍,32位乘法结果不会超过64位 7 8 int main() 9 { 10 unsigned int a = 0x13131313; 11 unsigned int b = 0x23232323; 12 unsigned int p = 0x00000001; 13 unsigned int temp = 0; 14 unsigned int flags; //用于判断做加法时是否溢出 15 int i; 16 int rlt[LEN] ={0}; //结果数组 17 18 for(i=0; i<LEN; i++) //主循环 19 { 20 flags = 0; 21 22 if(b&p) //判断是否需要做加法 23 { 24 flags = temp; 25 temp += a; 26 } 27 28 rlt[i] = (int) temp & 1; //最低位丢弃,并保存至数组 29 if(temp < flags) //判断是否溢出 30 temp += 0x80000000; 31 32 temp >>= 1; //右移结果 33 p <<= 1; 34 } 35 36 i = LEN-1; 37 while(rlt[i] == 0) i--; //丢弃结果前面的0 38 for(; i>=0; i--) //打印结果 39 printf("%d", rlt[i]); 40 41 printf("\n"); 42 43 return EXIT_SUCCESS; 44 } 45 #ifdef RESULT 46 D: 47 cd Cprogram 48 gcc axb.c 49 (echo #ifdef RESULT & doskey /history & a.exe & echo #endif) >> ./axb.c 50 1010011110001110011101010101101011110100000011010010011001 51 #endif
标签:style blog io color os sp for div log
原文地址:http://www.cnblogs.com/092-zhang/p/4162386.html