Here you can find the source of bcdToString(byte[] data, int offset, int length)
public static String bcdToString(byte[] data, int offset, int length)
//package com.java2s; /*/* w w w .j a v a2 s . c o m*/ * Copyright (C) 2006 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Many fields in GSM SIM's are stored as nibble-swizzled BCD * * Assumes left-justified field that may be padded right with 0xf * values. * * Stops on invalid BCD value, returning string so far */ public static String bcdToString(byte[] data, int offset, int length) { StringBuilder ret = new StringBuilder(length * 2); for (int i = offset; i < offset + length; i++) { byte b; int v; v = data[i] & 0xf; if (v > 9) break; ret.append((char) ('0' + v)); v = (data[i] >> 4) & 0xf; // Some PLMNs have 'f' as high nibble, ignore it if (v == 0xf) continue; if (v > 9) break; ret.append((char) ('0' + v)); } return ret.toString(); } }