Conversion of Algorithm →byte array and 16 binary see
Http://javaman.group.iteye.com/group/wiki/3405-cuisuqiang-google-socket-InputStream-OutputStream
Private Final Static byte[] hex = "0123456789ABCDEF". GetBytes ();Private Static intParseCharc) {if(c >= ' a ') return(C-' a ' +) & 0x0f; if(c >= ' A ') return(C-' A ' +) & 0x0f; return(c-' 0 ') & 0x0f;}//convert from byte array to hexadecimal string Public StaticString bytes2hexstring (byte[] b) {byte[] Buff =New byte[2 *B.length]; for(inti = 0; i < b.length; i++) {buff[2 * I] = hex[(B[i] >> 4) & 0x0f]; buff[2 * i + 1] = Hex[b[i] & 0x0f]; } return NewString (buff);}//convert from hexadecimal string to byte array Public Static byte[] hexstring2bytes (String hexstr) {byte[] B =New byte[Hexstr.length ()/2]; intj = 0; for(inti = 0; i < b.length; i++) { CharC0 = Hexstr.charat (j + +); CharC1 = Hexstr.charat (j + +); B[i]= (byte) ((Parse (C0) << 4) |Parse (C1)); } returnb;} Public Static voidMain (string[] args) {byte[] bt =New byte[]{10, 2, 12, 14, 1, 0, 0, 1, 0, 31, 45, 1, 8, 0, 1, 0,-96,-45, 10, 3}; System.out.println (Bytes2hexstring (BT)); System.out.println (arrays.tostring (Hexstring2bytes ("0a020c0e01000001001f2d0108000100a0d30a03")));}
Print
0a020c0e01000001001f2d0108000100a0d30a03[10, 2, 12, 14, 1, 0, 0, 1, 0, 31, 45, 1, 8, 0, 1, 0,-96, 45, 10, 3]
// returns an unsigned 2-binary representation of the 1110011 String hex = integer.tobinarystring (+); System.out.println (hex); // returns 2 binary string 1110011 corresponding value System.out.println (integer.valueof ("1110011", 2)); // 16 binary Value converted to binary System.out.println (Long.parselong ("a"); System.out.println (Long.parselong ("2F", 16));
Android Bluetooth (bluetooth®)