/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* Question: *
* How to calculate two integers each one has forty bit. *
* Algorithm: *
* Declare two arrays suppose to be array A and B to storage *
* the two integers just as a intacter singly. *
* Get the first number from array B,then use it to multiply *
* the number of array A singly. Declare another array C to *
* storage the value when multiplying. *
* Thinking about the carrying bits. *
* Thinking: *
* Can you use the Linear_List to do this? *
* If they are two floating numbers,so how to do it? *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
i = 0;
if (C[0] == 0) ++i; //To delete the primacy zero
for ( NULL; i < ARR_C_SIZE; i++)
{
printf("%d", C[i]);
}
getch();
printf("\n");
}
/*
* NOTICE:
* The Array C is not initialed,you should do that. Here
* the array is supposed to be filled zero.
* Algorithm:
*
*/
void Multiply( short A[], short B[], short C[], short A_size, short B_size)
{
short i = 0, j = 0, k = 1; // Assigned k to 1 to leave C[0]
//be null to storage the carrying.
for (j = 0; j<B_size; j++)
{
for (i = 0; i<A_size; i++)
{
C[k] += B[j] * A[i];
k++;
}
k = 2;
k = k + j;
}
}
// To solve the carrying .
void Carrying(short C[],short C_size)
{
short i, tens_place = 0, units_order = 0;
short temp = 0, end_arr;
end_arr = C_size-1;
for (i = end_arr; i >= 0; i--)
{
temp = C[i];
if (C[i] > 9)
{
tens_place = temp / 10;
units_order = temp % 10;
C[i-1] += tens_place;
C[i] = units_order;
}
}
}
2.Subtract the Divisor register from the left half of the Remainder register and
place the result in the left half of the Remainder register.
>>>>test Remainder
if Remainder>=0
3a.Shift the Remainder register to the left ,Seting the new rightmost bit 1
if Remainder <0
3b.Restore the original value by adding the Divisor register to the left half of
the Remainder register and place the sum in the half of the Remainder register.
Also shift the Remainder register to the left ,seting the new rightmost bit to 0