Android Byte Array to ASCII Convert Bcd2Ascii(byte[] bcd)

Here you can find the source of Bcd2Ascii(byte[] bcd)

Description

Bcd to Ascii(String)

Parameter

Parameter Description
bcd a parameter

Declaration

public static String Bcd2Ascii(byte[] bcd) 

Method Source Code

//package com.java2s;

public class Main {
    public final static char[] BToA = "0123456789abcdef".toCharArray();

    /**//  ww w  .ja v  a  2s  .c  o  m
     * Bcd to Ascii(String)
     * @param bcd
     * @return
     */
    public static String Bcd2Ascii(byte[] bcd) {
        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();
    }
}

Related

  1. toAsciiBytes(byte[] raw)
  2. toAsciiChars(byte[] raw)
  3. getBCD2(byte[] b, int offset)
  4. getBCD4(byte[] b, int offset)
  5. bcdToAscii(byte[] bcdByte)
  6. bcdToAscii(byte[] bcdByte, int offset, int length)