Byte.parseByte(): This method is available in the java.lang.Byte class of Java.
Syntax:
byte java.lang.Byte.parseByte(String s, int radix) throws NumberFormatException
This method takes two arguments, one of type String and another of type int as its parameters. This method parses the string argument as a signed byte in the radix specified by the second argument.
Parameters: Two parameters are required for this method.
s: the String containing the byte representation to be parsed.
radix: the radix to be used while parsings.
Returns: the byte value represented by the string argument in the specified radix.
Throws: NumberFormatException - If the string does not contain a parable byte.
For Example:
Byte.parseByte("101",2) = > It returns 5.
Approach
Java
public class ByteParseByteRadix {public static void main(String[] args) {String s = "101";int radix = 2;System.out.println(Byte.parseByte(s, radix));}}
Output:
5
No comments:
Post a Comment