Originariamente inviato da b4kk3
Beh, sempre in riferimento al programmino che dovevo fare (forse ti ricordi) per la moltiplicazione modulare
Ahhh sì, mi ricordo. 
Originariamente inviato da b4kk3
ho problemi con il complemento a due...cioè quando faccio il riporto del carry e lo faccio scorrere in avanti sommando e risommando, può capitare che alcuni numeri all'interno della stringa risultante diventino negativi perchè c'è considerato anche il bit di segno...quindi dovrei trovare il modo di non considerare quel bit...e il miglior modo per farlo è avere tipi di dato unsigned!:-(
Facciamo intanto una premessa: devi tenere il segno del tuo "big number" separato dall'array di "parole" (se ben ricordo ti avevo suggerito di usare degli int) che contiene il valore.
Il BigInteger di Java è fatto così:
codice:
...
public class BigInteger extends Number implements Comparable<BigInteger> {
/**
* The signum of this BigInteger: -1 for negative, 0 for zero, or
* 1 for positive. Note that the BigInteger zero must have
* a signum of 0. This is necessary to ensures that there is exactly one
* representation for each BigInteger value.
*
* @serial
*/
int signum;
/**
* The magnitude of this BigInteger, in big-endian order: the
* zeroth element of this array is the most-significant int of the
* magnitude. The magnitude must be "minimal" in that the most-significant
* int (<tt>mag[0]</tt>) must be non-zero. This is necessary to
* ensure that there is exactly one representation for each BigInteger
* value. Note that this implies that the BigInteger zero has a
* zero-length mag array.
*/
int[] mag;
....
Come vedi, segno e valore sono separati.
Per fare le somme tra 2 int, li devi convertire in long ma facendo in modo che la parte alta del long sia a 0. In questo modo il long del risultato NON verrà mai negativo.