这可能是一个简单的问题,但我无法找到答案。
我试图读取十六进制7B
,并将其转换为十进制整数(123),或者至少接收字符串7B
。
我的代码:
byte[] content = new byte[numCharsToRead];
while ((numBytesRead = bufferedInputStream.read(content, 0,
numCharsToRead)) != -1) {
String temp=new String(content);
Log.d("RS232",""+temp);
在logcat中输出:
答案 0 :(得分:0)
您可以尝试使用以下内容转换为int
:
String hexDigits = "7b"
int intValue = Integer.parseInt(hexDigits, 16);
此外,阅读部分可以简化为:
String temp;
while( (numBytesRead = bufferedInputStream.read(content, 0,
numCharsToRead)) != -1){
temp = new String(contents, 0, numBytesRead);
}