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, int radix) throws NumberFormatException 

Source Link

Document

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

Usage

From source file:net.jradius.client.gui.JRadiusSimulator.java

public byte[] toBinArray(String hexStr) {
    hexStr = hexStr.replace("0x", "");
    byte bArray[] = new byte[hexStr.length() / 2];
    for (int i = 0; i < (hexStr.length() / 2); i++) {
        byte firstNibble = Byte.parseByte(hexStr.substring(2 * i, 2 * i + 1), 16);
        byte secondNibble = Byte.parseByte(hexStr.substring(2 * i + 1, 2 * i + 2), 16);
        int finalByte = (secondNibble) | (firstNibble << 4);
        bArray[i] = (byte) finalByte;
    }//from  w w  w .  ja  v a 2  s  . c o  m
    return bArray;
}