Package java.math

Examples of java.math.BigInteger.bitCount()


      throw new AssertionFailedError("identified bug - sign bit not masked out of exponent");
    }
    assertEquals(2, hd.getBinaryExponent());
    BigInteger frac = hd.getSignificand();
    assertEquals(64, frac.bitLength());
    assertEquals(1, frac.bitCount());
  }

  public void testSubnormal() {
    ExpandedDouble hd = new ExpandedDouble(0x0000000000000001L);
View Full Code Here


      throw new AssertionFailedError("identified bug - subnormal numbers not decoded properly");
    }
    assertEquals(-1086, hd.getBinaryExponent());
    BigInteger frac = hd.getSignificand();
    assertEquals(64, frac.bitLength());
    assertEquals(1, frac.bitCount());
  }

  /**
   * Tests specific values for conversion from {@link ExpandedDouble} to {@link NormalisedDecimal} and back
   */
 
View Full Code Here

        int upperIndex = length;

        /* Count up to 2^13 - 1 and find all those values that have N bits on */
        for (int count = 0; count < 8192; count++) {
            BigInteger bi = new BigInteger(Integer.toString(count));
            if (bi.bitCount() != n) continue;
            // Reverse bits
            int reversed = 0;
            int reverseCount = count;
            for (int i = 0; i < 13; i++) {
                reversed = reversed << 1;
View Full Code Here

      assertTrue("a==b", a.equals(b));
      assertTrue("a >> i == bi3", a.shiftRight(i).equals(bi3));
      a = a.shiftLeft(1);
      assertTrue("<<1 == *2", b.multiply(two).equals(a));
      assertTrue("a non-neg", a.signum() >= 0);
      assertTrue("a.bitCount==b.bitCount", a.bitCount() == b.bitCount());

      BigInteger d = minusOne.shiftLeft(i);
      assertTrue("c==d", c.equals(d));
      c = c.shiftLeft(1);
      assertTrue("<<1 == *2 negative", d.multiply(two).equals(c));
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

        return Long.bitCount(a ^ b);
    }

    public static int hammingDistance(final BigInteger a, final BigInteger b) {
        BigInteger xor = a.xor(b);
        return xor.bitCount();
    }

}
View Full Code Here

        return val(Long.bitCount(a));
    }

    public IntWritable evaluate(String a) {
        BigInteger ai = new BigInteger(a);
        return val(ai.bitCount());
    }

    public IntWritable evaluate(List<Long> a) {
        int result = 0;
        for(int i = 0; i < a.size(); i++) {
View Full Code Here

     */
    public IntWritable evaluate(String a, String b) {
        BigInteger ai = new BigInteger(a);
        BigInteger bi = new BigInteger(b);
        BigInteger innerProduct = ai.and(bi);
        return val(innerProduct.bitCount());
    }

    /**
     * Count bits that both bits are 1.
     */
 
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.