Example usage for java.lang Short parseShort

List of usage examples for java.lang Short parseShort

Introduction

In this page you can find the example usage for java.lang Short parseShort.

Prototype

public static short parseShort(String s, int radix) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed short in the radix specified by the second argument.

Usage

From source file:Main.java

public static void main(String[] args) {
    System.out.println(Short.parseShort("10", 8));
}

From source file:MainClass.java

public static void main(String args[]) {
    String strOctal = "77";
    String strHex = "23";
    String strDecimal = "156";
    short o = Short.parseShort(strOctal, 8);
    short h = Short.parseShort("23", 16);
    short d = Short.parseShort(strDecimal, 10);
    int sum = o + h + d;
    System.out.println("The sum is " + sum);
}

From source file:Main.java

public static byte[] toBytesFromHexString(String digits) throws IllegalArgumentException {
    if (digits == null) {
        return null;
    }/*from  www.j av  a 2s  . c o m*/
    int length = digits.length();
    if (length % 2 == 1) {
        throw new IllegalArgumentException("For input string: \"" + digits + "\"");
    }
    length = length / 2;
    byte[] bytes = new byte[length];
    for (int i = 0; i < length; i++) {
        int index = i * 2;
        bytes[i] = (byte) (Short.parseShort(digits.substring(index, index + 2), 16));
    }
    return bytes;
}

From source file:Main.java

public static byte[] toBytes(String digits, int radix) throws IllegalArgumentException {
    if (digits == null) {
        return null;
    }// w  w w  .  ja  va 2  s. c om
    if (radix != 16 && radix != 10 && radix != 8) {
        throw new IllegalArgumentException("For input radix: \"" + radix + "\"");
    }
    int divLen = (radix == 16) ? 2 : 3;
    int length = digits.length();
    if (length % divLen == 1) {
        throw new IllegalArgumentException("For input string: \"" + digits + "\"");
    }
    length = length / divLen;
    byte[] bytes = new byte[length];
    for (int i = 0; i < length; i++) {
        int index = i * divLen;
        bytes[i] = (byte) (Short.parseShort(digits.substring(index, index + divLen), radix));
    }
    return bytes;
}

From source file:alluxio.security.authorization.ModeParser.java

private Mode parseNumeric(String value) {
    short s = Short.parseShort(value, 8);
    return new Mode(s);
}

From source file:hydrograph.ui.common.util.ConvertHexValues.java

private static char hexToChar(String hex) throws NumberFormatException {
    return (char) Short.parseShort(hex, 16);
}

From source file:com.bigstep.datalake.JsonUtil.java

private static FsPermission toFsPermission(final String s, Boolean aclBit, Boolean encBit) {
    FsPermission perm = new FsPermission(Short.parseShort(s, 8));
    final boolean aBit = (aclBit != null) ? aclBit : false;
    final boolean eBit = (encBit != null) ? encBit : false;
    if (aBit || eBit) {
        return new FsPermissionExtension(perm, aBit, eBit);
    } else {/*from  w  ww  . jav a  2  s. c  om*/
        return perm;
    }
}