Skip to content
Advertisement

Difference between 0x0A and 0x0D

I was studying about bluetooth and I was trying to write the code to keep listening to the input stream while connected and i came across this following code snippet:

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);
                }

Can someone explain what is the difference between 0x0A and 0x0D. And also give a brief explanation about this code. Kindly share your views.

Advertisement

Answer

The values starting 0x are hexadecimals. 0x0A is n newline character and 0x0D is r return character. You can read more about how to convert them here, or use the conversion chart

The code essentially runs different blocks of logic depending on what value of data is read from the mmInStream

Briefly:

  • when the data is 0x0A, the newline character n, it is skipped and not added to the arr_byte
  • when the data is 0x0D, the return character r, it builds a buffer from arr_byte and send the buffer to the UI Activity
  • when the data is any other character, it is added to arr_byte

Hope this helps.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement