Java Byte Create toByte(String string)

Here you can find the source of toByte(String string)

Description

to Byte

License

Open Source License

Declaration


public static byte toByte(String string) 

Method Source Code

//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;
    }
}

Related

  1. toByte(String hex)
  2. toByte(String hexStr)
  3. toByte(String hexString)
  4. toByte(String str)
  5. toByte(String string)
  6. toByte(String string)
  7. toByte(String value)
  8. toByte(String value)
  9. toByte(T value)