Here you can find the source of toByte(String string)
public static byte toByte(String string)
//package com.java2s; //License from project: Open Source License public class Main { public static byte toByte(String string) { return (byte) toInt(string); }// w w w .j a v a2s. c o m public static int toInt(String value) { if (!isBinary(value)) return 0; if (value.length() > 31) return Integer.MAX_VALUE; return Integer.parseInt(value, 2); } public static boolean isBinary(String binary) { if (binary == null || binary.length() == 0) return false; for (char c : binary.toCharArray()) if (!(c == '0' || c == '1')) return false; return true; } }