Cryptography Reference
In-Depth Information
private Int appendZeros(int places) {
//Make a new Int object
Int result=new Int();
//If this equals 0, return 0; no need to append
if (this.equals(ZERO)) return result;
//Make the resulting array larger
result.digits=new int[this.digits.length+places];
//Shift the digits into the new array
for (int i=0;i<this.digits.length;i++) {
result.digits[i]=this.digits[i];
}
return result;
}
Now, to multiply an Int by a single digit, we simply multiply each digit in the first operand
by the selected digit from the second operand. If this product is greater than 9, we use the
remainder of division by 10 for the corresponding digit in the result (plus a possible carry
from the previous multiplication), and we record the quotient when dividing by 10 as a
carry. Take the following example:
527
x 3
???
We first take 7 3 = 21; 1 becomes the digit in the one ' s column of the result, and 2
becomes the carry.
2
527
x 3
??1
3 = 6, and add the previous carry 2, to get 8. This becomes the digit in
the tens column of the result, and 0 becomes the carry.
We then take 2
0
527
x 3
?81
Now we take 5 3 = 15, and add the previous carry 0. 5 becomes the digit in the hun-
dreds column of the result, and 1 becomes the carry.
1
527
x 3
581
 
Search WWH ::




Custom Search