Android Bluetooth (bluetooth®)

Source: Internet
Author: User

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®)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.