G
Gast
Gast
Servus!
Ich schreibe gerade ein Programm das eine zahl einlesen soll, diese Zahl ist in Hex-Code. Ich habe eine Methode gefunden wie man nun die Zahl in ein Dezimales Zahlensystem umwandelt, wie soll ich die anwenden? Die Zahl ist schon in ein String umgewandelt!
Danke schon im voraus!
decode
public static Integer decode(String nm)
throws NumberFormatExceptionDecodes a String into an Integer. Accepts decimal, hexadecimal, and octal numbers given by the following grammar:
DecodableString:
Signopt DecimalNumeral
Signopt 0x HexDigits
Signopt 0X HexDigits
Signopt # HexDigits
Signopt 0 OctalDigits
Sign:
-
DecimalNumeral, HexDigits, and OctalDigits are defined in §3.10.1 of the Java Language Specification.
The sequence of characters following an (optional) negative sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the Integer.parseInt method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified String is the minus sign. No whitespace characters are permitted in the String.
Parameters:
nm - the String to decode.
Returns:
a Integer object holding the int value represented by nm
Throws:
NumberFormatException - if the String does not contain a parsable integer.
Since:
1.2
See Also:
parseInt(java.lang.String, int)
Ich schreibe gerade ein Programm das eine zahl einlesen soll, diese Zahl ist in Hex-Code. Ich habe eine Methode gefunden wie man nun die Zahl in ein Dezimales Zahlensystem umwandelt, wie soll ich die anwenden? Die Zahl ist schon in ein String umgewandelt!
Danke schon im voraus!
decode
public static Integer decode(String nm)
throws NumberFormatExceptionDecodes a String into an Integer. Accepts decimal, hexadecimal, and octal numbers given by the following grammar:
DecodableString:
Signopt DecimalNumeral
Signopt 0x HexDigits
Signopt 0X HexDigits
Signopt # HexDigits
Signopt 0 OctalDigits
Sign:
-
DecimalNumeral, HexDigits, and OctalDigits are defined in §3.10.1 of the Java Language Specification.
The sequence of characters following an (optional) negative sign and/or radix specifier ("0x", "0X", "#", or leading zero) is parsed as by the Integer.parseInt method with the indicated radix (10, 16, or 8). This sequence of characters must represent a positive value or a NumberFormatException will be thrown. The result is negated if first character of the specified String is the minus sign. No whitespace characters are permitted in the String.
Parameters:
nm - the String to decode.
Returns:
a Integer object holding the int value represented by nm
Throws:
NumberFormatException - if the String does not contain a parsable integer.
Since:
1.2
See Also:
parseInt(java.lang.String, int)