[英]Convert an ASCII numeric value into a character
I want to send numeric data from the terminal app as a ASCII with Bluetooth to the Android app, and inside the Android app, to convert ASCII numeric data to characters.我想通过蓝牙将终端应用程序中的数字数据作为 ASCII 发送到 Android 应用程序和 Android 应用程序内部,以将 ASCII 数字数据转换为字符。
I only found one solution, but it reads as a single byte.我只找到了一个解决方案,但它读取为单个字节。 I wrote this command for Android app to get data:
我为 Android 应用程序编写了这个命令来获取数据:
InputStream stream;
if (stream.available() > 0) {
int a = stream.read();
int x = Character.getNumericValue(a);
this.mmOutStream.write(x);
this.mmOutStream.flush();
}
This command这个命令
int a = stream.read (); /// 128
It takes the data as a ASCII and throws it inside a它将数据作为 ASCII 并将其放入
This command这个命令
int x = Character.getNumericValue(a); /// 1 2 8
ASCII converts to characters, but gives a single byte of data. ASCII 转换为字符,但提供单个字节的数据。 That is, I give the number as a ASCII, for example, the number 128 128 to converts to 1 2 8. But I want 128, but he gives it to me one by one.
也就是我给的数字是ASCII码,比如数字128 128要转换成1 2 8。但是我要128,他却一一给我。
You can cast an ASCII decimal value to char
as follows:您可以将 ASCII 十进制值转换为
char
,如下所示:
int ch = 125;
System.out.println((char) ch); // }
System.out.println(Character.getName(ch)); // RIGHT CURLY BRACKET
See also: Why do I get a number when I add chars?另请参阅:为什么添加字符时会得到一个数字?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.