Here you can find the source of asciiToBCD(byte[] ascii_buf, int asc_offset, byte[] bcd_buf, int bcd_offset, int conv_len, int type)
public static void asciiToBCD(byte[] ascii_buf, int asc_offset, byte[] bcd_buf, int bcd_offset, int conv_len, int type)
//package com.java2s; public class Main { public static void asciiToBCD(byte[] ascii_buf, int asc_offset, byte[] bcd_buf, int bcd_offset, int conv_len, int type) { int cnt;/*from w ww . ja v a 2 s . c o m*/ byte ch, ch1; int bcdOffset = bcd_offset; int asciiOffset = asc_offset; if (((conv_len & 0x01) > 0) && (type > 0)) { ch1 = 0; } else { ch1 = 0x55; } for (cnt = 0; cnt < conv_len; asciiOffset++, cnt++) { if (ascii_buf[asciiOffset] >= 97) // 97 = 'a' { ch = (byte) (ascii_buf[asciiOffset] - 97 + 10); // 97 = 'a' } else { if (ascii_buf[asciiOffset] >= 65) // 65 = 'A' { ch = (byte) ((ascii_buf[asciiOffset]) - 65 + 10); // 65 = 'A' } else { if (ascii_buf[asciiOffset] >= 48) // 48 = '0' { ch = (byte) ((ascii_buf[asciiOffset]) - 48); // 48 = '0' } else { ch = 0; } } } if (ch1 == 0x55) { ch1 = ch; } else { // *bcd_buf++=ch1<<4 | ch; bcd_buf[bcdOffset++] = (byte) ((ch1 << 4) | ch); ch1 = 0x55; } } if (ch1 != 0x55) { bcd_buf[bcdOffset] = (byte) (ch1 << 4); } } }