how to convert byte valueto hex and then to decimal which is from bluetooth spp device as hex value in android -


how convert 35 bytes of hex values decimal coming bluetooth serial port communnication.. using bluetooth chat application, device sending data in hex format of 35 bytes.... code giving output like: 10 oa ff 00 3c................11 code.. bluetoothservice.java

public void run() {              log.i(tag, "begin mconnectedthread");             byte[] buffer = new byte[35];             int bytes;                         // keep listening inputstream while connected             while (true) {                 try {                     // read inputstream                     bytes = mminstream.read(buffer, 0, buffer.length);                      // send obtained bytes ui activity                     mhandler.obtainmessage(mainactivity.message_read, bytes, -1, buffer)                             .sendtotarget();                 } catch (ioexception e) {                     log.e(tag, "disconnected", e);                     connectionlost();                     // start service on restart listening mode                     bluetoothservice.this.start();                     break;                 }             } 

mainactivity.java

byte[] readbuf = (byte[]) msg.obj;   string readmessage = bytestrans.bytes2hexstring(readbuf,msg.arg1);  marrayadapter.addall(mconnecteddevicename+":  "+ readmessage );  public static class bytestrans {          public static string bytes2hexstring(byte[] b, int count) {             string ret = "";             //string str ="";             (int = 0; < count; i++) {                 string hex = integer.tohexstring(b[i] & 0xff);                  if (hex.length() ==1) {                    hex = '0' + hex;                                    }                 ret += hex.touppercase() + " ";                                           }             return ret;         }` 

try following:

public static string bytes2string(byte[] b, int count) {         string ret = "";         //string str ="";         (int = 0; < count; i++) {             string myint = integer.tostring((int)(b[i] & 0xff));               ret.append(myint + " ");                                      }         return ret;     } 

i think may looking for.


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -