public static String bcdToString(byte[] data,int offset,int length){
  StringBuilder ret=new StringBuilder(length * 2);
  for (int i=offset; i < offset + length; i++) {
    int v;
    v=data[i] & 0xf;
    if (v > 9)     break;
    ret.append((char)('0' + v));
    v=(data[i] >> 4) & 0xf;
    if (v == 0xf)     continue;
    if (v > 9)     break;
    ret.append((char)('0' + v));
  }
  return ret.toString();
}

public static String bcdToString ( byte [ ] data , int offset , int length ) { StringBuilder ret = new StringBuilder ( length * 2 ) ; for ( int i = offset ; i < offset + length ; i ++ ) { int v ; v = data [ i ] & 0xf ; if ( v > 9 ) break ; ret . append ( ( char ) ( '0' + v ) ) ; v = ( data [ i ] > > 4 ) & 0xf ; if ( v == 0xf ) continue ; if ( v > 9 ) break ; ret . append ( ( char ) ( '0' + v ) ) ; } return ret . toString ( ) ; }
many fields in gsm sim ' s are stored as nibble - swizzled bcd < p / > assumes left - justified field that may be padded right with 0xf values . < p / > stops on invalid bcd value , returning string so far
