如何将java中1s和0s的String转换为相应的ASCII值?

时间:2011-12-09 11:11:55

标签: java string ascii

如何将java中的String与1和0转换为相应的ASCII值?

让我说我有

String str = "01101110";

如何将其转换为相应的'n',以便我可以打印n?

System.out.printl(str.toCorrespondingAscii());//output n

1 个答案:

答案 0 :(得分:3)

int value = Integer.parseInt("01101110", 2); //2 for binary
System.out.println(value);  // To print ascii

char digit = (char) value;
System.out.println(digit);  // To print n