Example usage for java.lang Long bitCount

List of usage examples for java.lang Long bitCount

Introduction

In this page you can find the example usage for java.lang Long bitCount.

Prototype

@HotSpotIntrinsicCandidate
public static int bitCount(long i) 

Source Link

Document

Returns the number of one-bits in the two's complement binary representation of the specified long value.

Usage

From source file:Main.java

public static void main(String[] args) {

    long l = 100;
    System.out.println("Number = " + l);

    System.out.println("Binary = " + Long.toBinaryString(l));

    System.out.println("Number of one bits = " + Long.bitCount(l));
}

From source file:com.github.joulupunikki.math.random.XorShift1024Star.java

public double stateOnes() {
    double r = 0;
    for (long t : s) {
        r += Long.bitCount(t);
    }/*from www  .j  av  a2 s .  c  o m*/
    return r / (WORD_BITS * STATE_WORDS);
}

From source file:chibi.gemmaanalysis.LinkMatrix.java

/**
 * @param mask/*from w w w.java 2s.c o m*/
 * @return
 */
public static int countBits(long[] mask) {
    int bits = 0;
    for (int i = 0; i < mask.length; i++)
        bits = bits + Long.bitCount(mask[i]);
    return bits;
}

From source file:com.google.uzaygezen.core.LongBitVector.java

@Override
public int cardinality() {
    return Long.bitCount(data);
}

From source file:chibi.gemmaanalysis.LinkMatrix.java

/**
 * @param mask1//from w  w w .  j ava  2 s .  c  o m
 * @param mask2
 * @return
 */
public static int overlapBits(long[] mask1, long[] mask2) {
    int bits = 0;
    for (int i = 0; i < mask1.length; i++)
        bits = bits + Long.bitCount(mask1[i] & mask2[i]);
    return bits;
}

From source file:es.udc.gii.common.eaf.stoptest.BitwiseConvergence.java

/**
 * Calculates the convergence rate between two individuals.
 *///from   w w w .j  a v a  2 s.co m
private double convergence(Individual i1, Individual i2) {

    double convergence = 0.0;

    /* Asume both individuals have the same number of genes !! */
    int genes = i1.getChromosomeAt(0).length;

    /* For each pair of genes */
    for (int i = 0; i < genes; i++) {

        /* Get the value of the genes. Note that only individuals which have
         * a double as an internal value are considered. */
        double d1 = i1.getChromosomeAt(0)[i];
        double d2 = i2.getChromosomeAt(0)[i];

        /* Get the binary codification of the values. */
        Long lg1 = new Long(Double.doubleToRawLongBits(d1));
        Long lg2 = new Long(Double.doubleToRawLongBits(d2));

        /* Perform a bitwise XOR operation. Bitpositions that are identical
         * will yield a 0 and bitpositions which differ will yield a 1. So
         * we are counting the bits in which the two individuals *differ* */
        Long lg = new Long(lg1.longValue() ^ lg2.longValue());

        /* Count the number of bits in which the two individuals differ. */
        convergence += Long.bitCount(lg);
    }

    /* Get the average bitwise difference. */
    convergence /= Long.SIZE * genes;

    /* Get the average convergence. */
    convergence = 1 - convergence;

    return convergence;
}

From source file:it.unimi.dsi.sux4j.mph.GOVMinimalPerfectHashFunction.java

/**
 * Counts the number of nonzero pairs of bits in a long.
 * //w w  w . jav a  2 s  .c  om
 * @param x a long.
 * @return the number of nonzero bit pairs in <code>x</code>.
 */

public final static int countNonzeroPairs(final long x) {
    return Long.bitCount((x | x >>> 1) & 0x5555555555555555L);
}

From source file:it.unimi.dsi.sux4j.mph.MinimalPerfectHashFunction.java

/**
 * Counts the number of nonzero pairs of bits in a long.
 * /*from  w  w  w. ja  v  a2s  .c o m*/
 * @param x a long.
 * @return the number of nonzero bit pairs in <code>x</code>.
 */

public static int countNonzeroPairs(final long x) {
    return Long.bitCount((x | x >>> 1) & 0x5555555555555555L);
}

From source file:com.google.uzaygezen.core.LongArrayBitVector.java

@Override
public int cardinality() {
    int result = 0;
    for (int i = 0; i < data.length; ++i) {
        result += Long.bitCount(data[i]);
    }//from ww  w . jav  a  2s.co  m
    return result;
}

From source file:com.cloudera.oryx.als.common.lsh.LocationSensitiveHash.java

public Collection<Iterator<LongObjectMap.MapEntry<float[]>>> getCandidateIterator(float[][] userVectors) {
    long[] bitSignatures = new long[userVectors.length];
    for (int i = 0; i < userVectors.length; i++) {
        bitSignatures[i] = toBitSignature(userVectors[i]);
    }/*ww w  .j a  v  a 2s  . c  o  m*/
    Collection<Iterator<LongObjectMap.MapEntry<float[]>>> inputs = Lists.newArrayList();
    for (LongObjectMap.MapEntry<long[]> entry : buckets.entrySet()) {
        for (long bitSignature : bitSignatures) {
            if (Long.bitCount(bitSignature ^ entry.getKey()) <= maxBitsDiffering) { // # bits differing
                inputs.add(new IDArrayToEntryIterator(entry.getValue()));
                break;
            }
        }
    }

    synchronized (newItems) {
        if (!newItems.isEmpty()) {
            // Have to clone because it's being written to
            inputs.add(new IDToEntryIterator(newItems.clone().iterator()));
        }
    }

    return inputs;
}