Android Utililty Methods Byte Array to ASCII Convert

List of utility methods to do Byte Array to ASCII Convert

Description

The list of methods to do Byte Array to ASCII Convert are organized into topic(s).

Method

byte[]toAsciiBytes(byte[] raw)
Converts an array of raw binary data into an array of ascii 0 and 1 character bytes - each byte is a truncated char.
if (raw == null || raw.length == 0) {
    return EMPTY_BYTE_ARRAY;
byte[] l_ascii = new byte[raw.length << 3];
for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) {
    for (int bits = 0; bits < BITS.length; ++bits) {
        if ((raw[ii] & BITS[bits]) == 0) {
            l_ascii[jj - bits] = '0';
...
char[]toAsciiChars(byte[] raw)
Converts an array of raw binary data into an array of ascii 0 and 1 characters.
if (raw == null || raw.length == 0) {
    return EMPTY_CHAR_ARRAY;
char[] l_ascii = new char[raw.length << 3];
for (int ii = 0, jj = l_ascii.length - 1; ii < raw.length; ii++, jj -= 8) {
    for (int bits = 0; bits < BITS.length; ++bits) {
        if ((raw[ii] & BITS[bits]) == 0) {
            l_ascii[jj - bits] = '0';
...
StringBcd2Ascii(byte[] bcd)
Bcd to Ascii(String)
StringBuffer sb = new StringBuffer(bcd.length * 2);
for (int i = 0; i < bcd.length; i++) {
    int h = ((bcd[i] & 0xF0) >> 4);
    int l = (bcd[i] & 0x0F);
    sb.append(BToA[h]).append(BToA[l]);
return sb.toString();
intgetBCD2(byte[] b, int offset)
get BCD
int ret = (b[offset + 1] & 0x0f);
ret += ((b[offset + 1] >>> 4) & 0x0f) * 10;
ret += (b[offset] & 0x0f) * 100;
ret += ((b[offset] >>> 4) & 0x0f) * 1000;
return ret;
intgetBCD4(byte[] b, int offset)
get BCD
int ret = (b[offset + 3] & 0x0f);
ret += ((b[offset + 3] >>> 4) & 0x0f) * 10;
ret += (b[offset + 2] & 0x0f) * 100;
ret += ((b[offset + 2] >>> 4) & 0x0f) * 1000;
ret += (b[offset + 1] & 0x0f) * 10000;
ret += ((b[offset + 1] >>> 4) & 0x0f) * 100000;
ret += (b[offset] & 0x0f) * 1000000;
ret += ((b[offset] >>> 4) & 0x0f) * 10000000;
...
byte[]bcdToAscii(byte[] bcdByte)
bcd To Ascii
byte[] returnByte = new byte[bcdByte.length * 2];
byte value;
for (int i = 0; i < bcdByte.length; i++) {
    value = (byte) (bcdByte[i] >> 4 & 0xF);
    if (value > 9) {
        returnByte[i * 2] = (byte) (value + (byte) 0x37);
    } else {
        returnByte[i * 2] = (byte) (value + (byte) 0x30);
...
byte[]bcdToAscii(byte[] bcdByte, int offset, int length)
bcd To Ascii
byte[] returnByte = new byte[length * 2];
byte value;
for (int i = offset; i < length; i++) {
    value = (byte) (bcdByte[i] >> 4 & 0xF);
    if (value > 9) {
        returnByte[i * 2] = (byte) (value + (byte) 0x37);
    } else {
        returnByte[i * 2] = (byte) (value + (byte) 0x30);
...
voidbcdToAscii(byte[] bcd_buf, int offset, byte[] ascii_buf, int asc_offset, int conv_len, int type)
bcd To Ascii
int cnt;
int bcdOffset = offset;
int asciiOffset = asc_offset;
if (conv_len > (bcd_buf.length * 2)) {
    conv_len = (bcd_buf.length * 2);
if (((conv_len & 0x01) > 0) && (type > 0)) {
    cnt = 1;
...
StringtoAsciiString(byte[] data)
to Ascii String
try {
    return data == null ? null : new String(data, "US-ASCII");
} catch (UnsupportedEncodingException e) {
    throw new IllegalStateException(e);
StringtoAsciiString(byte[] output)
to Ascii String
char[] chars = new char[output.length];
for (int i = 0; i < output.length; i++) {
    chars[i] = (char) output[i];
return new String(chars);