Example usage for java.lang Long toBinaryString

List of usage examples for java.lang Long toBinaryString

Introduction

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

Prototype

public static String toBinaryString(long i) 

Source Link

Document

Returns a string representation of the long argument as an unsigned integer in base 2.

Usage

From source file:org.apache.carbondata.core.util.CarbonUtil.java

private static int getBitLengthFullyFilled(int dimlens) {
    int bitsLength = Long.toBinaryString(dimlens).length();
    int div = bitsLength / 8;
    int mod = bitsLength % 8;
    if (mod > 0) {
        return 8 * (div + 1);
    } else {/* ww w .j a  v  a2s.  co m*/
        return bitsLength;
    }
}

From source file:CreditCardValidator.java

/**
 * Returns a 64 length String with the first flag on the right and the 
 * 64th flag on the left.  A 1 indicates the flag is on, a 0 means it's 
 * off./*  w w w.j av a2  s . c  o m*/
 *
 * @return string representation of this object.
 */
public String toString() {
    StringBuffer bin = new StringBuffer(Long.toBinaryString(this.flags));
    for (int i = 64 - bin.length(); i > 0; i--) {
        bin.insert(0, "0");
    }
    return bin.toString();
}

From source file:org.ohdsi.webapi.service.FeasibilityService.java

private String formatBitMask(Long n, int size) {
    return StringUtils.reverse(StringUtils.leftPad(Long.toBinaryString(n), size, "0"));
}

From source file:ome.model.utests.PermissionsTest.java

private void bitCompare(Role role, Right right) {
    Perms pp = new Perms().revoke(role, right);
    long l = pp.toLong();
    if (log.isDebugEnabled()) {
        log.debug(l + ":" + Long.toBinaryString(l));
    }/*from w w  w . ja  va2s.  co  m*/
    long bit = Perms.bit(role, right);
    if (log.isDebugEnabled()) {
        log.debug(bit + ":" + Long.toBinaryString(bit));
    }
    assertTrue((l ^ bit) == -1L);

}

From source file:org.carbondata.core.util.CarbonUtil.java

/**
 * This method will be used to update the dimension cardinality
 *
 * @param dimCardinality//  w  w  w  . ja  v a  2s. co m
 * @return new increment cardinality
 */
public static int[] getIncrementedCardinality(int[] dimCardinality) {
    // get the cardinality incr factor
    final int incrValue = Integer.parseInt(
            CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARDINALITY_INCREMENT_VALUE,
                    CarbonCommonConstants.CARDINALITY_INCREMENT_VALUE_DEFAULT_VAL));

    int perIncr = 0;
    int remainder = 0;
    int[] newDimsC = new int[dimCardinality.length];
    for (int i = 0; i < dimCardinality.length; i++) {
        // get the incr
        perIncr = (dimCardinality[i] * incrValue) / CONST_HUNDRED;

        // if per incr is more than one the add to cardinality
        if (perIncr > 0) {
            newDimsC[i] = dimCardinality[i] + perIncr;
        } else {
            // else add one
            newDimsC[i] = dimCardinality[i] + 1;
        }
        // check whether its in boundary condition
        remainder = newDimsC[i] % CONST_EIGHT;
        if (remainder == CONST_SEVEN) {
            // then incr cardinality by 1
            newDimsC[i] = dimCardinality[i] + 1;
        }
    }
    // get the log bits of cardinality
    for (int i = 0; i < newDimsC.length; i++) {
        newDimsC[i] = Long.toBinaryString(newDimsC[i]).length();
    }
    return newDimsC;
}

From source file:com.livinglogic.ul4.FunctionFormat.java

public static String call(long obj, String formatString, Locale locale) {
    IntegerFormat format = new IntegerFormat(formatString);

    if (locale == null)
        locale = Locale.ENGLISH;/*from w w  w .ja v  a 2  s  .c  o  m*/

    String output = null;

    boolean neg = obj < 0;
    if (neg)
        obj = -obj;

    switch (format.type) {
    case 'b':
        output = Long.toBinaryString(obj);
        break;
    case 'c':
        if (neg || obj > 0xffff)
            throw new RuntimeException("value out of bounds for c format");
        output = Character.toString((char) obj);
        break;
    case 'd':
        output = Long.toString(obj);
        break;
    case 'o':
        output = Long.toOctalString(obj);
        break;
    case 'x':
        output = Long.toHexString(obj);
        break;
    case 'X':
        output = Long.toHexString(obj).toUpperCase();
        break;
    case 'n':
        // FIXME: locale formatting
        output = Long.toString(obj);
        break;
    }
    return formatIntegerString(output, neg, format);
}

From source file:org.carbondata.core.util.CarbonUtil.java

public static int getIncrementedCardinality(int dimCardinality) {
    // get the cardinality incr factor
    final int incrValue = Integer.parseInt(
            CarbonProperties.getInstance().getProperty(CarbonCommonConstants.CARDINALITY_INCREMENT_VALUE,
                    CarbonCommonConstants.CARDINALITY_INCREMENT_VALUE_DEFAULT_VAL));

    int perIncr = 0;
    int remainder = 0;
    int newDimsC = 0;

    // get the incr
    perIncr = (dimCardinality * incrValue) / CONST_HUNDRED;

    // if per incr is more than one the add to cardinality
    if (perIncr > 0) {
        newDimsC = dimCardinality + perIncr;
    } else {/*from   w  w w.j  a v  a2s. c  om*/
        // else add one
        newDimsC = dimCardinality + 1;
    }
    // check whether its in boundary condition
    remainder = newDimsC % CONST_EIGHT;
    if (remainder == CONST_SEVEN) {
        // then incr cardinality by 1
        newDimsC = dimCardinality + 1;
    }
    newDimsC = Long.toBinaryString(newDimsC).length();
    // get the log bits of cardinality

    return newDimsC;
}

From source file:org.carbondata.core.util.CarbonUtil.java

/**
 * This method will be used to update the dimension cardinality
 *
 * @param dimCardinality/*from  www  .j  a  v a 2s  .c  o  m*/
 * @return new increment cardinality
 */
public static int getIncrementedFullyFilledRCDCardinalityFullyFilled(int dimCardinality) {
    int bitsLength = Long.toBinaryString(dimCardinality).length();
    int div = bitsLength / 8;
    int mod = bitsLength % 8;
    if (mod > 0) {
        dimCardinality = 8 * (div + 1);
    } else {
        dimCardinality = bitsLength;
    }
    return dimCardinality;
}

From source file:org.apache.hadoop.hive.ql.exec.persistence.BytesBytesMultiHashMap.java

private static String dumpRef(long ref) {
    return StringUtils.leftPad(Long.toBinaryString(ref), 64, "0") + " o=" + Ref.getOffset(ref) + " s="
            + Ref.getStateByte(ref) + " l=" + Ref.hasList(ref) + " h="
            + Long.toBinaryString(Ref.getHashBits(ref));
}

From source file:org.apache.hadoop.hive.ql.exec.persistence.BytesBytesMultiHashMap.java

private void debugDumpKeyProbe(long keyOffset, int keyLength, int hashCode, int finalSlot) {
    final int bucketMask = refs.length - 1;
    WriteBuffers.ByteSegmentRef fakeRef = new WriteBuffers.ByteSegmentRef(keyOffset, keyLength);
    writeBuffers.populateValue(fakeRef);
    int slot = hashCode & bucketMask;
    long probeSlot = slot;
    StringBuilder sb = new StringBuilder("Probe path debug for [");
    sb.append(Utils.toStringBinary(fakeRef.getBytes(), (int) fakeRef.getOffset(), fakeRef.getLength()));
    sb.append("] hashCode ").append(Integer.toBinaryString(hashCode)).append(" is: ");
    int i = 0;//from  ww  w  .j a va2  s .  c o  m
    while (slot != finalSlot) {
        probeSlot += (++i);
        slot = (int) (probeSlot & bucketMask);
        sb.append(slot).append(" - ").append(probeSlot).append(" - ").append(Long.toBinaryString(refs[slot]))
                .append("\n");
    }
    LOG.info(sb.toString());
}