Example usage for java.lang Long toString

List of usage examples for java.lang Long toString

Introduction

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

Prototype

public static String toString(long i, int radix) 

Source Link

Document

Returns a string representation of the first argument in the radix specified by the second argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Long.toString(10, 8));

    // returns a string representation of the specified long with radix 10
    String retval = Long.toString(1234567890, 10);
    System.out.println("Value = " + retval);

    // returns a string representation of the specified long with radix 16
    retval = Long.toString(1234567890, 16);
    System.out.println("Value = " + retval);

    // returns a string representation of the specified long with radix 8
    retval = Long.toString(1234567890, 8);
    System.out.println("Value = " + retval);
}

From source file:Main.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));

    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));

}

From source file:Main.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));

    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));
    System.out.println(Float.MIN_VALUE);
    System.out.println(Double.MAX_VALUE);
}

From source file:WrappedClassApp.java

public static void main(String args[]) {
    Boolean b1 = new Boolean("TRUE");
    Boolean b2 = new Boolean("FALSE");
    System.out.println(b1.toString() + " or " + b2.toString());
    for (int j = 0; j < 16; ++j)
        System.out.print(Character.forDigit(j, 16));
    System.out.println();/*from  w  w  w.j  a va  2 s  . c o m*/
    Integer i = new Integer(Integer.parseInt("ef", 16));
    Long l = new Long(Long.parseLong("abcd", 16));
    long m = l.longValue() * i.longValue();
    System.out.println(Long.toString(m, 8));
    System.out.println(Float.MIN_VALUE);
    System.out.println(Double.MAX_VALUE);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    String password = "secret";
    String algorithm = "SHA";

    byte[] plainText = password.getBytes();

    MessageDigest md = MessageDigest.getInstance(algorithm);

    md.reset();/*from   w  ww.  j a  v  a2s.  c o m*/
    md.update(plainText);
    byte[] encodedPassword = md.digest();

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < encodedPassword.length; i++) {
        if ((encodedPassword[i] & 0xff) < 0x10) {
            sb.append("0");
        }
        sb.append(Long.toString(encodedPassword[i] & 0xff, 16));
    }
    System.out.println("Plain    : " + password);
    System.out.println("Encrypted: " + sb.toString());
}

From source file:Main.java

public static String encodeHex(int integer) {
    String hexSTR = Long.toString(integer & 0xffffffff, 16);
    String returnStr = "00000000";
    int valid = returnStr.length() - hexSTR.length();
    if (valid > 0) {
        returnStr = returnStr.substring(0, valid) + hexSTR;
    } else {//  w  ww.j a v a  2  s .  co  m
        returnStr = hexSTR;
    }
    return returnStr;
}

From source file:Main.java

public static synchronized String getNonce() {
    SecureRandom sr = new SecureRandom();
    return Long.toString(Math.abs(sr.nextLong()), Character.MAX_RADIX);
}

From source file:Main.java

public static final String toHexString(byte[] bytes) {
    StringBuffer buffer = new StringBuffer(bytes.length * 2);
    for (int i = 0; i < bytes.length; i++) {
        if (((int) bytes[i] & 0xff) < 0x10)
            buffer.append("0");
        buffer.append(Long.toString((int) bytes[i] & 0xff, 16));
    }//  ww w .  ja  v a 2  s.  com
    return buffer.toString();
}

From source file:Main.java

/**
 * Turns array of bytes into string/*from   ww  w  . j a v a  2s  .c om*/
 * 
 * @param buf
 *            Array of bytes to convert to hex string
 * @return Generated hex string
 */
public static String asHex(byte buf[]) {
    StringBuffer strbuf = new StringBuffer(buf.length * 2);
    int i;

    for (i = 0; i < buf.length; i++) {
        if (((int) buf[i] & 0xff) < 0x10)
            strbuf.append("0");

        strbuf.append(Long.toString((int) buf[i] & 0xff, 16));
    }

    return strbuf.toString();
}

From source file:Main.java

public static String integerToHex(final Object value, final int desimals) {
    long tmp;// w w w .j av  a2 s.  c om
    if (value instanceof Byte) {
        tmp = ((Byte) value).byteValue() & 0xFF;
    } else if (value instanceof Short) {
        tmp = ((Short) value).shortValue() & 0xFFFF;
    } else if (value instanceof Long) {
        tmp = ((Long) value).longValue() & 0xFFFFFFFF;
    } else {
        tmp = ((Number) value).longValue();
    }
    String str = Long.toString(tmp, 16).toUpperCase();
    if (desimals == 0 || str.length() == zeroes.length()) {
        return str;
    }
    return zeroes.substring(0, desimals - str.length()) + str;
}