Description of Byte. parseByte (String s, int radix), intradix
1. Convert from basic data type to String
The String type provides the static method to convert the basic data type to the String type.
That is, the multiload method of the String. valueOf () parameter.
There are several
String. valueOf (boolean B): Convert boolean variable B to a String
String. valueOf (char c): Convert char variable c to String
String. valueOf (char [] data): converts the char array data to a String.
String. valueOf (char [] data, int offset, int count ):
Convert count elements from data [offset] In char array data into strings
String. valueOf (double d): Convert double variable d to String
String. valueOf (float f): converts the float variable f to a String.
String. valueOf (int I): converts int variable I to a String
String. valueOf (long l): converts long variable l to a String
String. valueOf (Object obj): converts an obj Object to a String, which is equal to obj. toString ()
Usage example:
Int I = 10;
String str = String. valueOf (I );
At this time, str will be "10"
2. Convert String to the basic data type of a number
Convert String to basic data type
Most of the packages that require basic data types
For example, convert String to byte
You can use Byte. parseByte (String s)
If this method cannot analyze s, NumberFormatException (Data Format exception) will be thrown)
Byte:
Byte. parseByte (String s): converts s to byte
Byte. parseByte (String s, int radix): converts s to byte Based on radix.
For example, Byte. parseByte ("11", 16) will get 17
Double:
Double. parseDouble (String s): Convert s to double
Float:
Double. parseFloat (String s): converts s to float
Int:
Integer. parseInt (String s): converts s to int
Long:
Long. parseLong (String)
Description of Byte. parseByte (String s, int radix)
Int radix refers to the base number, that is, the base number of the base number.
For example, in your example
B [0] = Byte. parseByte ("11", 2) = 3
It indicates that the byte value of string 11 in decimal format is 3 based on 2, and here 11 represents a binary number.
B [0] = Byte. parseByte ("11", 3) = 4
It indicates that the byte value of string 11 in decimal format is 4 based on 3, and here 11 represents a three-digit number.
If the string you give cannot be converted, or the base number is less than 2 or greater than 36, an exception is thrown.
For example
B [0] = Byte. parseByte ("12", 2)
// In the binary system, only 1 and 0 are supported.
B [0] = Byte. parseByte ("12", 1)