在Java(Android)中将十六进制数转换为十进制

br1*_*br1 1 java android

如上面的标题.我想从一个十六进制数字EditText

EditText number = (EditText) findViewById (R.id.etDisplay);
Editable stringEditable = number.getText().toString;
String nuovo = stringEditable.toString();
Run Code Online (Sandbox Code Playgroud)

我想转换nuovodecimal number.

pix*_*xel 28

int i = Integer.parseInt(nuovo, 16);
Run Code Online (Sandbox Code Playgroud)

  • Integer.parseInt("DEADBEEF",16)抛出数字格式异常 (4认同)

Tho*_*mas 5

尝试Integer.parseInt(nuovo,16)


ban*_*ing 5

接受的答案在某些情况下有效,但如果您的数字可能大于Integer.MAX_VALUE,您可能需要使用以下内容:

public static long hexToLong(String hex) {
    return Long.parseLong(hex, 16);
}
Run Code Online (Sandbox Code Playgroud)