本文整理汇总了C#中BigInteger.cutOffLeadingZeroes方法的典型用法代码示例。如果您正苦于以下问题:C# BigInteger.cutOffLeadingZeroes方法的具体用法?C# BigInteger.cutOffLeadingZeroes怎么用?C# BigInteger.cutOffLeadingZeroes使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BigInteger
的用法示例。
在下文中一共展示了BigInteger.cutOffLeadingZeroes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: multiplyPAP
//.........这里部分代码省略.........
* <td>a<sub>2</sub></td>
* <td>a<sub>1</sub></td>
* <td>a<sub>0</sub></td>
* <td></td>
* <td></td>
* </tr>
*
*<tr>
* <td align="center">B=</td>
* <td></td>
* <td>b<sub>2</sub></td>
* <td>b<sub>1</sub></td>
* <td>b<sub>1</sub></td>
* <td></td>
* <td></td>
* </tr>
*
* <tr>
* <td></td>
* <td></td>
* <td></td>
* <td>b<sub>0</sub>*a<sub>3</sub></td>
* <td>b<sub>0</sub>*a<sub>2</sub></td>
* <td>b<sub>0</sub>*a<sub>1</sub></td>
* <td>b<sub>0</sub>*a<sub>0</sub></td>
* </tr>
*
* <tr>
* <td></td>
* <td></td>
* <td>b<sub>1</sub>*a<sub>3</sub></td>
* <td>b<sub>1</sub>*a<sub>2</sub></td>
* <td>b<sub>1</sub>*a1</td>
* <td>b<sub>1</sub>*a0</td>
* </tr>
*
* <tr>
* <td>+</td>
* <td>b<sub>2</sub>*a<sub>3</sub></td>
* <td>b<sub>2</sub>*a<sub>2</sub></td>
* <td>b<sub>2</sub>*a<sub>1</sub></td>
* <td>b<sub>2</sub>*a<sub>0</sub></td>
* </tr>
*
*<tr>
* <td></td>
*<td>______</td>
* <td>______</td>
* <td>______</td>
* <td>______</td>
* <td>______</td>
* <td>______</td>
*</tr>
*
* <tr>
*
* <td align="center">A*B=R=</td>
* <td align="center">r<sub>5</sub></td>
* <td align="center">r<sub>4</sub></td>
* <td align="center">r<sub>3</sub></td>
* <td align="center">r<sub>2</sub></td>
* <td align="center">r<sub>1</sub></td>
* <td align="center">r<sub>0</sub></td>
* <td></td>
* </tr>
*
* </tbody>
* </table>
*
*</tt>
*
* @param op1 first factor of the multiplication {@code op1 >= 0}
* @param op2 second factor of the multiplication {@code op2 >= 0}
* @return a {@code BigInteger} of value {@code op1 * op2}
*/
internal static BigInteger multiplyPAP(BigInteger a, BigInteger b)
{
// PRE: a >= b
int aLen = a.numberLength;
int bLen = b.numberLength;
int resLength = aLen + bLen;
int resSign = (a.sign != b.sign) ? -1 : 1;
// A special case when both numbers don't exceed int
if (resLength == 2) {
long val = unsignedMultAddAdd(a.digits[0], b.digits[0], 0, 0);
int valueLo = (int)val;
int valueHi = (int)java.dotnet.lang.Operator.shiftRightUnsignet (val, 32);
return ((valueHi == 0)
? new BigInteger(resSign, valueLo)
: new BigInteger(resSign, 2, new int[]{valueLo, valueHi}));
}
int[] aDigits = a.digits;
int[] bDigits = b.digits;
int[] resDigits = new int[resLength];
// Common case
multArraysPAP(aDigits, aLen, bDigits, bLen, resDigits);
BigInteger result = new BigInteger(resSign, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例2: inplaceShiftRight
/**
* Performs {@code val >>= count} where {@code val} is a positive number.
*/
internal static void inplaceShiftRight(BigInteger val, int count)
{
int sign = val.signum();
if (count == 0 || val.signum() == 0)
return;
int intCount = count >> 5; // count of integers
val.numberLength -= intCount;
if (!shiftRight(val.digits, val.numberLength, val.digits, intCount,
count & 31)
&& sign < 0) {
// remainder not zero: add one to the result
int i;
for (i = 0; ( i < val.numberLength ) && ( val.digits[i] == -1 ); i++) {
val.digits[i] = 0;
}
if (i == val.numberLength) {
val.numberLength++;
}
val.digits[i]++;
}
val.cutOffLeadingZeroes();
val.unCache();
}
示例3: inplaceAdd
/**
* Performs {@code op1 += op2}. {@code op1} must have enough place to store
* the result (i.e. {@code op1.bitLength() >= op2.bitLength()}). Both
* should be positive (i.e. {@code op1 >= op2}).
*
* @param op1 the input minuend, and the output result.
* @param op2 the addend
*/
internal static void inplaceAdd(BigInteger op1, BigInteger op2)
{
// PRE: op1 >= op2 > 0
add (op1.digits, op1.digits, op1.numberLength, op2.digits,
op2.numberLength);
op1.numberLength = java.lang.Math.min (java.lang.Math.max (op1.numberLength,
op2.numberLength) + 1, op1.digits.Length);
op1.cutOffLeadingZeroes ();
op1.unCache();
}
示例4: subtract
/** @see BigInteger#subtract(BigInteger) */
internal static BigInteger subtract(BigInteger op1, BigInteger op2)
{
int resSign;
int[] resDigits;
int op1Sign = op1.sign;
int op2Sign = op2.sign;
if (op2Sign == 0) {
return op1;
}
if (op1Sign == 0) {
return op2.negate ();
}
int op1Len = op1.numberLength;
int op2Len = op2.numberLength;
if (op1Len + op2Len == 2) {
long a = ( op1.digits[0] & 0xFFFFFFFFL );
long b = ( op2.digits[0] & 0xFFFFFFFFL );
if (op1Sign < 0) {
a = -a;
}
if (op2Sign < 0) {
b = -b;
}
return BigInteger.valueOf (a - b);
}
int cmp = ( ( op1Len != op2Len ) ? ( ( op1Len > op2Len ) ? 1 : -1 )
: Elementary.compareArrays (op1.digits, op2.digits, op1Len) );
if (cmp == BigInteger.LESS) {
resSign = -op2Sign;
resDigits = ( op1Sign == op2Sign ) ? subtract (op2.digits, op2Len,
op1.digits, op1Len) : add (op2.digits, op2Len, op1.digits,
op1Len);
} else {
resSign = op1Sign;
if (op1Sign == op2Sign) {
if (cmp == BigInteger.EQUALS) {
return BigInteger.ZERO;
}
resDigits = subtract (op1.digits, op1Len, op2.digits, op2Len);
} else {
resDigits = add (op1.digits, op1Len, op2.digits, op2Len);
}
}
BigInteger res = new BigInteger (resSign, resDigits.Length, resDigits);
res.cutOffLeadingZeroes ();
return res;
}
示例5: finalSubtraction
/**
* Performs the final reduction of the Montgomery algorithm.
* @see monPro(BigInteger, BigInteger, BigInteger, long)
* @see monSquare(BigInteger, BigInteger, long)
*/
internal static BigInteger finalSubtraction(int []res, BigInteger modulus)
{
// skipping leading zeros
int modulusLen = modulus.numberLength;
bool doSub = res[modulusLen]!=0;
if(!doSub) {
int[] modulusDigits = modulus.digits;
doSub = true;
for(int i = modulusLen - 1; i >= 0; i--) {
if(res[i] != modulusDigits[i]) {
doSub = (res[i] != 0) && ((res[i] & 0xFFFFFFFFL) > (modulusDigits[i] & 0xFFFFFFFFL));
break;
}
}
}
BigInteger result = new BigInteger(1, modulusLen+1, res);
// if (res >= modulusDigits) compute (res - modulusDigits)
if (doSub) {
Elementary.inplaceSubtract(result, modulus);
}
result.cutOffLeadingZeroes();
return result;
}
示例6: completeInPlaceAdd
/**
* Same as @link #inplaceAdd(BigInteger, BigInteger), but without the restriction of
* non-positive values
* @param op1 any number
* @param op2 any number
*/
internal static void completeInPlaceAdd(BigInteger op1, BigInteger op2)
{
if (op1.sign == 0)
java.lang.SystemJ.arraycopy (op2.digits, 0, op1.digits, 0, op2.numberLength);
else if (op2.sign == 0)
return;
else if (op1.sign == op2.sign)
add (op1.digits, op1.digits, op1.numberLength, op2.digits,
op2.numberLength);
else {
int sign = unsignedArraysCompare(op1.digits,
op2.digits, op1.numberLength, op2.numberLength);
if (sign > 0)
subtract (op1.digits, op1.digits, op1.numberLength, op2.digits,
op2.numberLength);
else {
inverseSubtract (op1.digits, op1.digits, op1.numberLength,
op2.digits, op2.numberLength);
op1.sign = -op1.sign;
}
}
op1.numberLength = java.lang.Math.max (op1.numberLength, op2.numberLength) + 1;
op1.cutOffLeadingZeroes ();
op1.unCache();
}
示例7: orNegative
/** @return sign = -1, magnitude = -(-val.magnitude | -that.magnitude) */
internal static BigInteger orNegative(BigInteger val, BigInteger that)
{
// PRE: val and that are negative;
// PRE: val has at least as many trailing zeros digits as that
int iThat = that.getFirstNonzeroDigit();
int iVal = val.getFirstNonzeroDigit();
int i;
if (iVal >= that.numberLength) {
return that;
}else if (iThat >= val.numberLength) {
return val;
}
int resLength = java.lang.Math.min(val.numberLength, that.numberLength);
int[] resDigits = new int[resLength];
//Looking for the first non-zero digit of the result
if (iThat == iVal) {
resDigits[iVal] = -(-val.digits[iVal] | -that.digits[iVal]);
i = iVal;
} else {
for (i = iThat; i < iVal; i++) {
resDigits[i] = that.digits[i];
}
resDigits[i] = that.digits[i] & (val.digits[i] - 1);
}
for (i++; i < resLength; i++) {
resDigits[i] = val.digits[i] & that.digits[i];
}
BigInteger result = new BigInteger(-1, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例8: shiftRight
/** @see BigInteger#shiftRight(int) */
internal static BigInteger shiftRight(BigInteger source, int count)
{
int intCount = count >> 5; // count of integers
count &= 31; // count of remaining bits
if (intCount >= source.numberLength) {
return ((source.sign < 0) ? BigInteger.MINUS_ONE : BigInteger.ZERO);
}
int i;
int resLength = source.numberLength - intCount;
int []resDigits = new int[resLength + 1];
shiftRight(resDigits, resLength, source.digits, intCount, count);
if (source.sign < 0) {
// Checking if the dropped bits are zeros (the remainder equals to
// 0)
for (i = 0; (i < intCount) && (source.digits[i] == 0); i++) {
;
}
// If the remainder is not zero, add 1 to the result
if ((i < intCount)
|| ((count > 0) && ((source.digits[i] << (32 - count)) != 0))) {
for (i = 0; (i < resLength) && (resDigits[i] == -1); i++) {
resDigits[i] = 0;
}
if (i == resLength) {
resLength++;
}
resDigits[i]++;
}
}
BigInteger result = new BigInteger(source.sign, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例9: andPositive
/** @return sign = 1, magnitude = val.magnitude & that.magnitude*/
internal static BigInteger andPositive(BigInteger val, BigInteger that)
{
// PRE: both arguments are positive
int resLength = java.lang.Math.min(val.numberLength, that.numberLength);
int i = java.lang.Math.max(val.getFirstNonzeroDigit(), that.getFirstNonzeroDigit());
if (i >= resLength) {
return BigInteger.ZERO;
}
int []resDigits = new int[resLength];
for ( ; i < resLength; i++) {
resDigits[i] = val.digits[i] & that.digits[i];
}
BigInteger result = new BigInteger(1, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例10: orDiffSigns
/** @return sign = -1, magnitude = -(positive.magnitude | -negative.magnitude) */
internal static BigInteger orDiffSigns(BigInteger positive, BigInteger negative)
{
// Jumping over the least significant zero bits
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
int i;
int limit;
// Look if the trailing zeros of the positive will "copy" all
// the negative digits
if (iPos >= negative.numberLength) {
return negative;
}
int resLength = negative.numberLength;
int[] resDigits = new int[resLength];
if (iNeg < iPos ) {
// We know for sure that this will
// be the first non zero digit in the result
for (i = iNeg; i < iPos; i++) {
resDigits[i] = negative.digits[i];
}
} else if (iPos < iNeg) {
i = iPos;
resDigits[i] = -positive.digits[i];
limit = java.lang.Math.min(positive.numberLength, iNeg);
for(i++; i < limit; i++ ) {
resDigits[i] = ~positive.digits[i];
}
if (i != positive.numberLength) {
resDigits[i] = ~(-negative.digits[i] | positive.digits[i]);
} else{
for (; i<iNeg; i++) {
resDigits[i] = -1;
}
// resDigits[i] = ~(-negative.digits[i] | 0);
resDigits[i] = negative.digits[i] - 1;
}
i++;
} else {// iNeg == iPos
// Applying two complement to negative and to result
i = iPos;
resDigits[i] = -(-negative.digits[i] | positive.digits[i]);
i++;
}
limit = java.lang.Math.min(negative.numberLength, positive.numberLength);
for (; i < limit; i++) {
// Applying two complement to negative and to result
// resDigits[i] = ~(~negative.digits[i] | positive.digits[i] );
resDigits[i] = negative.digits[i] & ~positive.digits[i];
}
for( ; i < negative.numberLength; i++) {
resDigits[i] = negative.digits[i];
}
BigInteger result = new BigInteger(-1, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例11: andNotPositiveNegative
/** @return sign = 1, magnitude = positive.magnitude & ~(-negative.magnitude)*/
internal static BigInteger andNotPositiveNegative(BigInteger positive, BigInteger negative)
{
// PRE: positive > 0 && negative < 0
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
if (iNeg >= positive.numberLength) {
return positive;
}
int resLength = java.lang.Math.min(positive.numberLength, negative.numberLength);
int []resDigits = new int[resLength];
// Always start from first non zero of positive
int i = iPos;
for ( ; i < iNeg; i++) {
// resDigits[i] = positive.digits[i] & -1 (~0)
resDigits[i] = positive.digits[i];
}
if (i == iNeg) {
resDigits[i] = positive.digits[i] & (negative.digits[i] - 1);
i++;
}
for ( ; i < resLength; i++) {
// resDigits[i] = positive.digits[i] & ~(~negative.digits[i]);
resDigits[i] = positive.digits[i] & negative.digits[i];
}
BigInteger result = new BigInteger(1, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例12: andNotPositive
/** @return sign = 1, magnitude = val.magnitude & ~that.magnitude*/
internal static BigInteger andNotPositive(BigInteger val, BigInteger that)
{
// PRE: both arguments are positive
int []resDigits = new int[val.numberLength];
int limit = java.lang.Math.min(val.numberLength, that.numberLength);
int i;
for (i = val.getFirstNonzeroDigit(); i < limit; i++) {
resDigits[i] = val.digits[i] & ~that.digits[i];
}
for ( ; i < val.numberLength; i++) {
resDigits[i] = val.digits[i];
}
BigInteger result = new BigInteger(1, val.numberLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例13: andNotNegative
/** @return sign = 1, magnitude = -val.magnitude & ~(-that.magnitude)*/
internal static BigInteger andNotNegative(BigInteger val, BigInteger that)
{
// PRE: val < 0 && that < 0
int iVal = val.getFirstNonzeroDigit();
int iThat = that.getFirstNonzeroDigit();
if (iVal >= that.numberLength) {
return BigInteger.ZERO;
}
int resLength = that.numberLength;
int[] resDigits = new int[resLength];
int limit;
int i = iVal;
if (iVal < iThat) {
// resDigits[i] = -val.digits[i] & -1;
resDigits[i] = -val.digits[i];
limit = java.lang.Math.min(val.numberLength, iThat);
for (i++; i < limit; i++) {
// resDigits[i] = ~val.digits[i] & -1;
resDigits[i] = ~val.digits[i];
}
if (i == val.numberLength) {
for ( ; i < iThat; i++) {
// resDigits[i] = -1 & -1;
resDigits[i] = -1;
}
// resDigits[i] = -1 & ~-that.digits[i];
resDigits[i] = that.digits[i] - 1;
} else {
// resDigits[i] = ~val.digits[i] & ~-that.digits[i];
resDigits[i] = ~val.digits[i] & (that.digits[i] - 1);
}
} else if (iThat < iVal ) {
// resDigits[i] = -val.digits[i] & ~~that.digits[i];
resDigits[i] = -val.digits[i] & that.digits[i];
} else {
// resDigits[i] = -val.digits[i] & ~-that.digits[i];
resDigits[i] = -val.digits[i] & (that.digits[i] - 1);
}
limit = java.lang.Math.min(val.numberLength, that.numberLength);
for (i++; i < limit; i++) {
// resDigits[i] = ~val.digits[i] & ~~that.digits[i];
resDigits[i] = ~val.digits[i] & that.digits[i];
}
for ( ; i < that.numberLength; i++) {
// resDigits[i] = -1 & ~~that.digits[i];
resDigits[i] = that.digits[i];
}
BigInteger result = new BigInteger(1, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例14: shiftLeft
/** @see BigInteger#shiftLeft(int) */
internal static BigInteger shiftLeft(BigInteger source, int count)
{
int intCount = count >> 5;
count &= 31; // %= 32
int resLength = source.numberLength + intCount
+ ( ( count == 0 ) ? 0 : 1 );
int []resDigits = new int[resLength];
shiftLeft(resDigits, source.digits, intCount, count);
BigInteger result = new BigInteger(source.sign, resLength, resDigits);
result.cutOffLeadingZeroes();
return result;
}
示例15: xorDiffSigns
//.........这里部分代码省略.........
int[] resDigits;
int iNeg = negative.getFirstNonzeroDigit();
int iPos = positive.getFirstNonzeroDigit();
int i;
int limit;
//The first
if (iNeg < iPos) {
resDigits = new int[resLength];
i = iNeg;
//resDigits[i] = -(-negative.digits[i]);
resDigits[i] = negative.digits[i];
limit = java.lang.Math.min(negative.numberLength, iPos);
//Skip the positive digits while they are zeros
for (i++; i < limit; i++) {
//resDigits[i] = ~(~negative.digits[i]);
resDigits[i] = negative.digits[i];
}
//if the negative has no more elements, must fill the
//result with the remaining digits of the positive
if (i == negative.numberLength) {
for ( ; i < positive.numberLength; i++) {
//resDigits[i] = ~(positive.digits[i] ^ -1) -> ~(~positive.digits[i])
resDigits[i] = positive.digits[i];
}
}
} else if (iPos < iNeg) {
resDigits = new int[resLength];
i = iPos;
//Applying two complement to the first non-zero digit of the result
resDigits[i] = -positive.digits[i];
limit = java.lang.Math.min(positive.numberLength, iNeg);
for (i++; i < limit; i++) {
//Continue applying two complement the result
resDigits[i] = ~positive.digits[i];
}
//When the first non-zero digit of the negative is reached, must apply
//two complement (arithmetic negation) to it, and then operate
if (i == iNeg) {
resDigits[i] = ~(positive.digits[i] ^ -negative.digits[i]);
i++;
} else {
//if the positive has no more elements must fill the remaining digits with
//the negative ones
for ( ; i < iNeg; i++) {
// resDigits[i] = ~(0 ^ 0)
resDigits[i] = -1;
}
for ( ; i < negative.numberLength; i++) {
//resDigits[i] = ~(~negative.digits[i] ^ 0)
resDigits[i] = negative.digits[i];
}
}
} else {
int digit;
//The first non-zero digit of the positive and negative are the same
i = iNeg;
digit = positive.digits[i] ^ -negative.digits[i];
if (digit == 0) {
limit = java.lang.Math.min(positive.numberLength, negative.numberLength);
for (i++; i < limit && (digit = positive.digits[i] ^ ~negative.digits[i]) == 0; i++)
;
if (digit == 0) {
// shorter has only the remaining virtual sign bits
for ( ; i < positive.numberLength && (digit = ~positive.digits[i]) == 0; i++)
;
for ( ; i < negative.numberLength && (digit = ~negative.digits[i]) == 0; i++)
;
if (digit == 0) {
resLength = resLength + 1;
resDigits = new int[resLength];
resDigits[resLength - 1] = 1;
BigInteger result = new BigInteger(-1, resLength, resDigits);
return result;
}
}
}
resDigits = new int[resLength];
resDigits[i] = -digit;
i++;
}
limit = java.lang.Math.min(negative.numberLength, positive.numberLength);
for ( ; i < limit; i++) {
resDigits[i] = ~(~negative.digits[i] ^ positive.digits[i]);
}
for ( ; i < positive.numberLength; i++) {
// resDigits[i] = ~(positive.digits[i] ^ -1)
resDigits[i] = positive.digits[i];
}
for ( ; i < negative.numberLength; i++) {
// resDigits[i] = ~(0 ^ ~negative.digits[i])
resDigits[i] = negative.digits[i];
}
BigInteger result1 = new BigInteger(-1, resLength, resDigits);
result1.cutOffLeadingZeroes();
return result1;
}