/** * Encodes a byte array into a hex string (hex dump). * @deprecated Please see class HexUtil */ @Deprecated public static String encodeHex(byte[] data, char delimiter) { // the result StringBuilder result = new StringBuilder(); short val = 0; // encode each byte into a hex dump for (int i = 0; i < data.length; i++) { val = decodeUnsigned(data[i]); result.append(padLeading(Integer.toHexString((int) val), 2)); result.append(delimiter); } // return encoded text return result.toString(); }
/** * BCD encodes a String into a byte array. */ public static byte[] encodeBcd(String data, int num_bytes) { // allocate buffer byte buf[] = new byte[num_bytes]; // if length of addr is odd, then add an F onto the end of it if ((data.length() % 2) != 0) { data += "F"; } int index = 0; for (int i = 0; i < data.length(); i += 2) { StringBuilder x = new StringBuilder(data.substring(i, i + 2)); x.reverse(); buf[index] = ByteUtil.decodeHex(x.toString(), 2)[0]; index++; } return buf; }
int userDataHeaderLength = ByteUtil.decodeUnsigned(shortMessage[0]) + 1;
/** * BCD decodes a byte array into a String. For example, addresses inside * PDUs for SMS are usually BCD encoded. An address of "13134434272" will * actually look like this inside the byte[] "31314443722F" * * len is the number of bytes * to read. */ public static String decodeBcd(byte[] data, int offset, int len) { StringBuilder result = new StringBuilder(); // loop through byte array until we get to the end or an F for (int i = offset; i < (offset + len); i++) { // get buffer StringBuilder x = new StringBuilder(encodeHex(data[i])); // reverse it x.reverse(); // add it to the data if (x.charAt(1) == 'F' || x.charAt(1) == 'f') { result.append(x.substring(0, 1)); } else { result.append(x.toString()); } } return result.toString(); }
int userDataHeaderLength = ByteUtil.decodeUnsigned(shortMessage[0]) + 1;
/** * BCD decodes a byte array into a String. For example, addresses inside * PDUs for SMS are usually BCD encoded. An address of "13134434272" will * actually look like this inside the byte[] "31314443722F" * * len is the number of bytes * to read. */ public static String decodeBcd(byte[] data, int offset, int len) { StringBuilder result = new StringBuilder(); // loop through byte array until we get to the end or an F for (int i = offset; i < (offset + len); i++) { // get buffer StringBuilder x = new StringBuilder(encodeHex(data[i])); // reverse it x.reverse(); // add it to the data if (x.charAt(1) == 'F' || x.charAt(1) == 'f') { result.append(x.substring(0, 1)); } else { result.append(x.toString()); } } return result.toString(); }
/** * Encodes a byte array into a hex string (hex dump). * @deprecated Please see class HexUtil */ @Deprecated public static String encodeHex(byte[] data, char delimiter) { // the result StringBuilder result = new StringBuilder(); short val = 0; // encode each byte into a hex dump for (int i = 0; i < data.length; i++) { val = decodeUnsigned(data[i]); result.append(padLeading(Integer.toHexString((int) val), 2)); result.append(delimiter); } // return encoded text return result.toString(); }
int userDataHeaderLength = ByteUtil.decodeUnsigned(shortMessage[0]) + 1;
/** * BCD encodes a String into a byte array. */ public static byte[] encodeBcd(String data, int num_bytes) { // allocate buffer byte buf[] = new byte[num_bytes]; // if length of addr is odd, then add an F onto the end of it if ((data.length() % 2) != 0) { data += "F"; } int index = 0; for (int i = 0; i < data.length(); i += 2) { StringBuilder x = new StringBuilder(data.substring(i, i + 2)); x.reverse(); buf[index] = ByteUtil.decodeHex(x.toString(), 2)[0]; index++; } return buf; }
int userDataHeaderLength = ByteUtil.decodeUnsigned(shortMessage[0]) + 1;