List of usage examples for java.lang Long numberOfLeadingZeros
@HotSpotIntrinsicCandidate public static int numberOfLeadingZeros(long i)
From source file:Main.java
public static void main(String[] args) { System.out.println(Long.numberOfLeadingZeros(123123)); }
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:Main.java
/** * @param delta/*from w w w . ja v a 2 s. c o m*/ * @return */ private static int getNumBits(final long delta) { return Long.SIZE - Long.numberOfLeadingZeros(delta); }
From source file:Main.java
public static int getVNumSize(long i) { if (i >= -112 && i <= 127) { return 1; }//from ww w . java 2s.c om if (i < 0) { i ^= -1L; // take one's complement' } // find the number of bytes with non-leading zeros int dataBits = Long.SIZE - Long.numberOfLeadingZeros(i); // find the number of data bytes + length byte return (dataBits + 7) / 8 + 1; }
From source file:Main.java
public static byte[] dataBytesForLong(long value, int minBytes) { // every 8 leading zeros is one less byte (than 8) needed int numBytes = 8 - (Long.numberOfLeadingZeros(value) / 8); if (numBytes < minBytes) numBytes = minBytes;// w w w .java 2s. co m byte[] bytes = new byte[numBytes]; // big-endian, least significant bytes at end for (int i = 0; i < bytes.length; i++) { bytes[bytes.length - i - 1] = (byte) (value & 0xFF); value >>>= 8; } return bytes; }
From source file:Main.java
/** * Returns the number of contiguous 0 bits starting with the most significant * bit of x.//from w w w . ja va 2 s . c om */ static int countLeadingZeros(long x) { return Long.numberOfLeadingZeros(x); }
From source file:com.google.uzaygezen.core.LongBitVector.java
/** * Unsafe constructor. Keep it private.//www . j a va 2 s. c o m */ private LongBitVector(int size, long data) { assert 64 - Long.numberOfLeadingZeros(data) <= size; this.size = size; this.data = data; mask = size == 0 ? 0 : WORD_MASK >>> BITS_PER_WORD - size; }
From source file:com.kylinolap.common.hll.HyperLogLogPlusCounter.java
protected void add(long hash) { int bucketMask = m - 1; int bucket = (int) (hash & bucketMask); int firstOnePos = Long.numberOfLeadingZeros(hash | bucketMask) + 1; if (firstOnePos > registers[bucket]) registers[bucket] = (byte) firstOnePos; }
From source file:com.google.uzaygezen.core.LongBitVector.java
@Override public int length() { return BITS_PER_WORD - Long.numberOfLeadingZeros(data); }
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 ww w. j av a2 s. com*/ int lowestSetBit = Long.numberOfTrailingZeros(value); for (int i = lowestSetBit; i < bitLength; ++i) { if ((value & 1L << i) != 0) { bitset.set(i); } } }