Java ASCII AsciiBTAddressToBytes(String btAddress)

Here you can find the source of AsciiBTAddressToBytes(String btAddress)

Description

Converts a nicely formatted Bluetooth address to string of bytes representing the address

License

Open Source License

Parameter

Parameter Description
btAddress ASCII version of address

Return

Bytes version of address or null of error

Declaration

public static byte[] AsciiBTAddressToBytes(String btAddress) 

Method Source Code

//package com.java2s;
/*****************************************************************
BioZen/*  w w w  . j  a  va2 s. co m*/
    
Copyright (C) 2011 The National Center for Telehealth and 
Technology
    
Eclipse Public License 1.0 (EPL-1.0)
    
This library is free software; you can redistribute it and/or
modify it under the terms of the Eclipse Public License as
published by the Free Software Foundation, version 1.0 of the 
License.
    
The Eclipse Public License is a reciprocal license, under 
Section 3. REQUIREMENTS iv) states that source code for the 
Program is available from such Contributor, and informs licensees 
how to obtain it in a reasonable manner on or through a medium 
customarily used for software exchange.
    
Post your updates and modifications to our GitHub or email to 
t2@tee2.org.
    
This library is distributed WITHOUT ANY WARRANTY; without 
the implied warranty of MERCHANTABILITY or FITNESS FOR A 
PARTICULAR PURPOSE.  See the Eclipse Public License 1.0 (EPL-1.0)
for more details.
     
You should have received a copy of the Eclipse Public License
along with this library; if not, 
visit http://www.opensource.org/licenses/EPL-1.0
    
*****************************************************************/

public class Main {
    /**
     * Converts a nicely formatted Bluetooth address to string of bytes representing the address
     * 
     * @param btAddress   ASCII version of address
     * @return            Bytes version of address or null of error
     */
    public static byte[] AsciiBTAddressToBytes(String btAddress) {
        // Make sure the address is of the form xx:xx:xx:xx:xx:xx
        // If not return null
        if (btAddress.length() != 17)
            return null;
        String[] tokens = btAddress.split(":");
        if (tokens.length != 6)
            return null;

        byte[] finalResult = new byte[tokens.length];
        int i = 0;
        for (String val : tokens) {
            finalResult[i++] = Integer.decode("0x" + val).byteValue();
        }

        return finalResult;

    }
}

Related

  1. ascii(final int c)
  2. ascii(String string)
  3. ascii2Bcd(byte[] asc)
  4. ascii2BCD(byte[] val, int len)
  5. asciiBytes(String x)
  6. asciiChar(int value)
  7. asciiChars()
  8. asciiCharToBytes(char[] chars)