Package java.math

Examples of java.math.BigInteger.bitCount()


  }

  // slow version used for testing
  static long gcd(long l1, long l2) {
    final BigInteger gcd = BigInteger.valueOf(l1).gcd(BigInteger.valueOf(l2));
    assert gcd.bitCount() <= 64;
    return gcd.longValue();
  }

  public void testGCD() {
    final int iters = atLeast(100);
View Full Code Here


   * bitCount() of a negative number.
   */
  public void testBitCountNeg() {
    BigInteger aNumber = new BigInteger(
        "-12378634756382937873487638746283767238657872368748726875");
    assertEquals(87, aNumber.bitCount());
  }

  /**
   * bitCount() of a negative number.
   */
 
View Full Code Here

   * bitCount() of a negative number.
   */
  public void testBitCountPos() {
    BigInteger aNumber = new BigInteger(
        "12378634756343564757582937873487638746283767238657872368748726875");
    assertEquals(107, aNumber.bitCount());
  }

  /**
   * bitCount() of zero.
   */
 
View Full Code Here

  /**
   * bitCount() of zero.
   */
  public void testBitCountZero() {
    BigInteger aNumber = new BigInteger("0");
    assertEquals(0, aNumber.bitCount());
  }

  /**
   * bitLength() of a negative number.
   */
 
View Full Code Here

    /**
     * bitCount() of zero.
     */
    public void testBitCountZero() {
        BigInteger aNumber = new BigInteger("0");
        assertEquals(0, aNumber.bitCount());
    }

    /**
     * bitCount() of a negative number.
     */
 
View Full Code Here

    /**
     * bitCount() of a negative number.
     */
    public void testBitCountNeg() {
        BigInteger aNumber = new BigInteger("-12378634756382937873487638746283767238657872368748726875");
        assertEquals(87, aNumber.bitCount());
    }

    /**
     * bitCount() of a negative number.
     */
 
View Full Code Here

    /**
     * bitCount() of a negative number.
     */
    public void testBitCountPos() {
        BigInteger aNumber = new BigInteger("12378634756343564757582937873487638746283767238657872368748726875");
        assertEquals(107, aNumber.bitCount());
    }

    /**
     * bitLength() of zero.
     */
 
View Full Code Here

    bb.put((byte)0xff).put((byte)0xff).put((byte)0xff).put((byte)0xff);
    bb.position(0);
    bb.limit(8);
    BigInteger bi = Unsigned.getUnsignedLong(bb);
    BigInteger uLongMax = new BigInteger(ULONG_MAX);
    for (int i = 0; i < uLongMax.bitCount(); ++i) {
        TestCase.assertTrue("Bit: " + i + " should be: " + uLongMax.testBit(i),
                uLongMax.testBit(i) == bi.testBit(i));
    }
    TestCase.assertEquals(ULONG_MAX, bi.toString());
View Full Code Here

    bb.put((byte)0x00);
    bb.position(0);
    bb.limit(10);
    bi = Unsigned.getUnsignedLong(bb, 1);
    uLongMax = new BigInteger(ULONG_MAX);
    for (int i = 0; i < uLongMax.bitCount(); ++i) {
        TestCase.assertTrue("Bit: " + i + " should be: " + uLongMax.testBit(i),
                uLongMax.testBit(i) == bi.testBit(i));
    }
    TestCase.assertEquals(ULONG_MAX, bi.toString());
  }
View Full Code Here

            for (int j=0; j<32; j++) {
                bitCount += ((tmp & 1) == bit ? 1 : 0);
                tmp >>= 1;
            }

            if (bigX.bitCount() != bitCount) {
                //System.err.println(x+": "+bitCount+", "+bigX.bitCount());
                failCount++;
            }
        }
        report("Bit Count", failCount);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.