1 /*2 Binary multiplication3 */4#include <stdio.h>5#include <stdlib.h>6 #defineLEN 64//twice times the number of factor bits, 32-bit multiplication result will not exceed 64 bits7 8 intMain ()9 {TenUnsignedintA =0x13131313; OneUnsignedintb =0x23232323; AUnsignedintp =0x00000001; -Unsignedinttemp =0; -UnsignedintFlags//used to determine if an overflow was made when adding the inti; - intRlt[len] ={0};//result Array - - for(i=0; i<len; i++)//Main Loop + { -Flags =0; + A if(b&p)//decide if you need to do the addition at { -Flags =temp; -Temp + =A; - } - -Rlt[i] = (int) Temp &1;//the lowest bit is discarded and saved to the array in if(Temp < flags)//Determine if overflow -Temp + =0x80000000; to +Temp >>=1;//Right Shift result -P <<=1; the } * $i = len-1;Panax Notoginseng while(Rlt[i] = =0) i--;//discard results in front of 0 - for(; i>=0; i--)//Print Results theprintf"%d", Rlt[i]); + Aprintf"\ n"); the + returnexit_success; - } $ #ifdef RESULT $ D: - CD Cprogram - gcc AXB.C the(Echo #ifdef RESULT & doskey/history & A.exe & Echo#endif) >>./AXB.C - 1010011110001110011101010101101011110100000011010010011001Wuyi #endif
C to implement binary multiplication