0x0A 和 0x0D 的区别
Difference between 0x0A and 0x0D
我正在研究蓝牙,我正在尝试编写代码以在连接时继续收听输入流,我遇到了以下代码片段:
int data = mmInStream.read();
if(data == 0x0A) {
} else if(data == 0x0D) {
buffer = new byte[arr_byte.size()];
for(int i = 0 ; i < arr_byte.size() ; i++) {
buffer[i] = arr_byte.get(i).byteValue();
}
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothState.MESSAGE_READ
, buffer.length, -1, buffer).sendToTarget();
arr_byte = new ArrayList<Integer>();
} else {
arr_byte.add(data);
}
谁能解释一下 0x0A 和 0x0D 的区别。并对这段代码进行简要说明。
欢迎分享你的看法。
以 0x
开头的值为十六进制。 0x0A
是 \n
换行符, 0x0D
是 \r
return 字符。您可以阅读有关如何转换它们的更多信息 here, or use the conversion chart
根据从 mmInStream
中读取 data
的值,代码基本上运行不同的逻辑块
简要说明:
- 当
data
为0x0A
时,换行符\n
被跳过,不加到arr_byte
- 当
data
为0x0D
时,return字符\r
,它从arr_byte
构建一个缓冲区,并将缓冲区发送到UIActivity
- 当
data
是任何其他字符时,它被添加到arr_byte
希望这对您有所帮助。
我正在研究蓝牙,我正在尝试编写代码以在连接时继续收听输入流,我遇到了以下代码片段:
int data = mmInStream.read();
if(data == 0x0A) {
} else if(data == 0x0D) {
buffer = new byte[arr_byte.size()];
for(int i = 0 ; i < arr_byte.size() ; i++) {
buffer[i] = arr_byte.get(i).byteValue();
}
// Send the obtained bytes to the UI Activity
mHandler.obtainMessage(BluetoothState.MESSAGE_READ
, buffer.length, -1, buffer).sendToTarget();
arr_byte = new ArrayList<Integer>();
} else {
arr_byte.add(data);
}
谁能解释一下 0x0A 和 0x0D 的区别。并对这段代码进行简要说明。 欢迎分享你的看法。
以 0x
开头的值为十六进制。 0x0A
是 \n
换行符, 0x0D
是 \r
return 字符。您可以阅读有关如何转换它们的更多信息 here, or use the conversion chart
根据从 mmInStream
data
的值,代码基本上运行不同的逻辑块
简要说明:
- 当
data
为0x0A
时,换行符\n
被跳过,不加到arr_byte
- 当
data
为0x0D
时,return字符\r
,它从arr_byte
构建一个缓冲区,并将缓冲区发送到UIActivity - 当
data
是任何其他字符时,它被添加到arr_byte
希望这对您有所帮助。