Example usage for java.lang Long numberOfTrailingZeros

List of usage examples for java.lang Long numberOfTrailingZeros

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public static int numberOfTrailingZeros(long i) 

Source Link

Document

Returns the number of zero bits following the lowest-order ("rightmost") one-bit 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("Lowest one bit = " + Long.lowestOneBit(l));

    System.out.print("Number of leading zeros = ");
    System.out.println(Long.numberOfLeadingZeros(l));

    System.out.print("Number of trailing zeros = ");
    System.out.println(Long.numberOfTrailingZeros(l));
}

From source file:io.horizondb.io.BitSet.java

public int writerIndex() {

    return Long.numberOfTrailingZeros(this.writingMask);
}

From source file:io.horizondb.io.BitSet.java

public int readerIndex() {

    return Long.numberOfTrailingZeros(this.readingMask);
}

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

@Override
public int nextClearBit(int fromIndex) {
    Preconditions.checkArgument(fromIndex >= 0);
    if (fromIndex >= size) {
        return -1;
    }//from ww w . j a v a2 s  .co  m
    long w = ~data & (WORD_MASK << fromIndex);
    int tcb = Long.numberOfTrailingZeros(w);
    return tcb == size ? -1 : tcb;
}

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

@Override
public int nextSetBit(int fromIndex) {
    Preconditions.checkArgument(fromIndex >= 0);
    if (fromIndex >= size) {
        return -1;
    }//from   w w  w  .j a v  a 2  s  . c  o m
    long w = data & (WORD_MASK << fromIndex);
    int tcb = Long.numberOfTrailingZeros(w);
    return tcb == 64 ? -1 : tcb;
}

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

public void copyFrom(long value) {
    int bitLength = 64 - Long.numberOfLeadingZeros(value);
    Preconditions.checkArgument(bitLength <= size, "value doesn't fit");
    bitset.clear();//from   w w  w  .j  a  va2 s  .c  o m
    int lowestSetBit = Long.numberOfTrailingZeros(value);
    for (int i = lowestSetBit; i < bitLength; ++i) {
        if ((value & 1L << i) != 0) {
            bitset.set(i);
        }
    }
}

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

@Override
public int nextSetBit(int fromIndex) {
    Preconditions.checkArgument(fromIndex >= 0);
    if (fromIndex >= size) {
        return -1;
    }/*www .j ava 2  s  .  c  om*/
    int fromBucket = fromIndex / WORD;
    long word = data[fromBucket] & -(1L << fromIndex);
    while (word == 0L && ++fromBucket < data.length) {
        word = data[fromBucket];
    }
    if (fromBucket == data.length) {
        return -1;
    }
    int result = WORD * fromBucket + Long.numberOfTrailingZeros(word);
    assert 0 <= result & result < size;
    return result;
}

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

@Override
public int nextClearBit(int fromIndex) {
    Preconditions.checkArgument(fromIndex >= 0);
    if (fromIndex >= size) {
        return -1;
    }//  w w w.j a  v a  2s.c  om
    int fromBucket = fromIndex / WORD;
    long word = data[fromBucket] & -(1L << fromIndex);
    while (word == -1L && ++fromBucket < data.length) {
        word = data[fromBucket];
    }
    if (fromBucket == data.length) {
        return -1;
    }
    int result = WORD * fromBucket + Long.numberOfTrailingZeros(~word);
    return result >= size ? -1 : result;
}

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

@Override
public int lowestDifferentBit() {
    long localData = data;
    final int value;
    if ((localData & 0x1L) == 0) {
        if (localData == 0) {
            value = 0;//w  ww  .ja v a  2s.c om
        } else {
            value = Long.numberOfTrailingZeros(localData);
        }
    } else {
        if (localData == mask) {
            value = 0;
        } else {
            value = Long.numberOfTrailingZeros(~localData);
        }
    }
    assert value == 0 || (0 < value & value < size);
    return value;
}

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

@Override
public int lowestDifferentBit() {
    if (size == 0) {
        return 0;
    }/*from w  w  w .  j  a va  2 s.c om*/
    int i;
    boolean last = (data[0] & 1L) != 0;
    for (i = 0; i < data.length && data[i] == (last ? -1L : 0L); ++i)
        ;
    /* All bits in data[i-1], data[i-1], ..., data[0] are equal to last... */
    if (i == data.length) {
        return 0;
    }
    /* ... and in data[i] there is a bit != last. */
    int result = WORD * i + Long.numberOfTrailingZeros(last ? ~data[i] : data[i]);
    return result >= size ? 0 : result;
}