C to implement binary multiplication

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.