Multiply Big Data

Source: Internet
Author: User
Tags array to string

Using system;using system.collections.generic;using system.linq;using system.text;namespace BigNumberMultiplication {class Program {static void Main (string[] args) {try {int fir                st = 4916;                int second = 12345;                Long result = First * second; Console.WriteLine (String. Format ("{0} * {1} = {2}\n\n", first. ToString (), second. ToString (), result.                ToString ()));                String firststr = "100000000000000000000";                String secondstr = "100000000000000000000";                String resultstr = Multipfunction (Firststr, SECONDSTR);                Console.WriteLine ("The result is: {0}", Resultstr.trimstart (' 0 ')); Console.WriteLine ("The length of the result is: {0}", Resultstr.trimstart (' 0 ').                Length);            Console.readkey (); } catch (Exception ex) {}}//Big Data multiplication private static string Multipfunction (Strin G fiRstnumstr, String secondnumstr) {try {int firstnumlength = Firstnumstr.lengt                H                int secondnumlength = Secondnumstr.length;                int resultnumlength = firstnumlength + secondnumlength;                int[] Firstnumvalue = new Int[firstnumlength];                int[] Secondnumvalue = new Int[secondnumlength];                int[] Resultnumvalue = new Int[resultnumlength];                    Iterates through a string, converting each bit of character into an int shape insert shaping array for the for (int i = 0; i < firstnumlength; i++) {                Firstnumvalue[i] = firstnumstr[i]-48; } for (int i = 0; i < secondnumlength; i++) {Secondnumvalue[i] = Seco                Ndnumstr[i]-48;                }//defined array initialization each bit is 0, so the following procedure can be assigned 0 to omit for (int i = 0; i < resultnumlength; i++)                {Resultnumvalue[i] = 0; }//algorithmThe core (the process of the primary written calculation multiplication), multiply the two digits by the bitwise--and the group composition result of the shaping array//Then the result of the shaping array to traverse, the result of the low-order to append to the adjacent high, low-Yu Yu to the low (note: Here said the low is exactly the high point of the array Large bit) for (int i = firstNumLength-1; I >= 0; i--) {for (int j = Seco NdNumLength-1; J >= 0;                        j--) {resultnumvalue[i + j + 1] + = firstnumvalue[i] * Secondnumvalue[j];                        Resultnumvalue[i + j] + = Resultnumvalue[i + J +1]/10;                    Resultnumvalue[i + j + 1] = resultnumvalue[i + j + 1]% 10;                }}//Convert an array into a character array char[] temp = new Char[resultnumlength];                 for (int i = 0; i < resultnumlength; i++) {Temp[i] = (char) (Resultnumvalue[i] + 48);                }//Converts the character array to string resultstr = new String (temp);            return resultstr; } catch (Exception ex) {               return string.            Empty; }        }    }}

  

Multiply Big Data

Related Article

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.