Example usage for java.lang Byte parseByte

List of usage examples for java.lang Byte parseByte

Introduction

In this page you can find the example usage for java.lang Byte parseByte.

Prototype

public static byte parseByte(String s) throws NumberFormatException 

Source Link

Document

Parses the string argument as a signed decimal byte .

Usage

From source file:Main.java

public static void main(String[] argv) throws Exception {
    byte b = Byte.parseByte("123");
    System.out.println(b);/*from   w  ww.  j  a  va  2  s.  com*/
}

From source file:Main.java

public static void main(String[] args) {
    System.out.println("parse string to byte:" + Byte.parseByte("10"));
}

From source file:Main.java

public static void main(String[] args) {
    String str = new String("10");
    byte b = Byte.parseByte(str);
    System.out.println(b);//  www .  jav  a2s  . com
}

From source file:Main.java

public static byte doByte(Object obj) {
    return obj != null ? Byte.parseByte(obj.toString()) : 0;
}

From source file:Main.java

private static byte bits2byteReverse(String bString) {
    byte result = 0;
    for (int i = 0, j = 0; i < 8; i++, j++) {
        result += (Byte.parseByte(bString.charAt(i) + "") * Math.pow(2, j));
    }/*from w w w  .  j a  va 2s .  c om*/
    return result;
}

From source file:Main.java

private static byte bits2byte(String bString) {
    byte result = 0;
    for (int i = bString.length() - 1, j = 0; i >= 0; i--, j++) {
        result += (Byte.parseByte(bString.charAt(i) + "") * Math.pow(2, j));
    }/*from  ww  w .  ja  v  a2  s . co m*/
    return result;
}

From source file:Main.java

public static byte doByte(Object obj, byte defValue) {
    return obj != null ? Byte.parseByte(obj.toString()) : defValue;
}

From source file:Main.java

public static final byte getByteAttribute(final Attributes pAttributes, final String pAttributeName,
        final byte pDefaultValue) {
    final String value = pAttributes.getValue("", pAttributeName);
    return (value != null) ? Byte.parseByte(value) : pDefaultValue;
}

From source file:Main.java

public static int IPAddr2int(String IPAddr) {
    byte[] ip = new byte[4];
    int position1 = IPAddr.indexOf(".");
    int position2 = IPAddr.indexOf(".", position1 + 1);
    int position3 = IPAddr.indexOf(".", position2 + 1);
    ip[0] = Byte.parseByte(IPAddr.substring(0, position1));
    ip[1] = Byte.parseByte(IPAddr.substring(position1 + 1, position2));
    ip[2] = Byte.parseByte(IPAddr.substring(position2 + 1, position3));
    ip[3] = Byte.parseByte(IPAddr.substring(position3 + 1));
    return bytes2int(ip, 0);
}

From source file:Main.java

public static byte parse(String str, byte fallback) {
    try {//w w w .  ja v a  2 s.  c o m
        return Byte.parseByte(str);
    } catch (NumberFormatException e) {
        return fallback;
    }
}