Android Unicode Convert asciiToBCD(byte[] ascii_buf, int asc_offset, byte[] bcd_buf, int bcd_offset, int conv_len, int type)

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)

Description

ascii To BCD

Declaration

public static void asciiToBCD(byte[] ascii_buf, int asc_offset,
            byte[] bcd_buf, int bcd_offset, int conv_len, int type) 

Method Source Code

//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);
        }
    }
}

Related

  1. unicodePreservingIndex(String str, int index)
  2. fullWidthToHalfWidth(String s)
  3. getEncodedSize(String value)
  4. halfWidthToFullWidth(String s)
  5. bytes2StringUNICODE(byte[] buf, int offset, int length, boolean bigEndian)
  6. convertToUnicodeByteArray(String s)
  7. convertToUnicode(byte[] b, boolean includesNull)
  8. stringToUnicode(String strText)
  9. unicode2han3last_direct(Character c)