将ascii转换为int?

我得到一个ASCII值,我想将其转换为Ineger因为我知道它的整数ASCII值..

int a=53 

这是5的ASCII值我希望将其转换为整数

 int asciiValue = 53; int numericValue = Character.getNumericValue(asciiValue); System.out.println(numericValue); 

如果你确定它是一个int,你可以使用Integer.parseInt();

如果可以保证字符串包含整数:

  Integer.parseInt(String) 

使用:

 try { int i = Integer.parseInt(StringValue); } catch (NumberFormatException nfe) { System.out.println("NumberFormatException: " + nfe.getMessage()); } 

你的意思是单个字符还是字符串?

 char ch = int n = Character.forDigit(ch, 10); 

要么

 int n = ch - '0'; 

使用Integer.parseInt(String)或者如果只使用单个字符: int n = (int) (_char - '0')