Java ASCII asciiToBCD(byte[] ascii, int asc_len)

Here you can find the source of asciiToBCD(byte[] ascii, int asc_len)

Description

ascii To BCD

License

Open Source License

Declaration

private static byte[] asciiToBCD(byte[] ascii, int asc_len) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private static byte[] asciiToBCD(byte[] ascii, int asc_len) {
        byte[] bcd = new byte[asc_len / 2];
        int j = 0;
        for (int i = 0; i < (asc_len + 1) / 2; i++) {
            bcd[i] = asc_to_bcd(ascii[j++]);
            bcd[i] = (byte) (((j >= asc_len) ? 0x00 : asc_to_bcd(ascii[j++])) + (bcd[i] << 4));
        }/*from  w  w w .j  av  a  2 s .  com*/
        return bcd;
    }

    private static byte asc_to_bcd(byte asc) {
        byte bcd;

        if ((asc >= '0') && (asc <= '9'))
            bcd = (byte) (asc - '0');
        else if ((asc >= 'A') && (asc <= 'F'))
            bcd = (byte) (asc - 'A' + 10);
        else if ((asc >= 'a') && (asc <= 'f'))
            bcd = (byte) (asc - 'a' + 10);
        else
            bcd = (byte) (asc - 48);
        return bcd;
    }
}

Related

  1. asciiPaddingR(String str, int length, String padding)
  2. asciiQuads(String word)
  3. asciiString(byte[] bytes, int from, int count)
  4. asciiString(String fourcc)
  5. AsciiStringToString(String content)
  6. asciiToEbcdic(String s)
  7. ASCIIToInteger(String ascii)
  8. asciiValue(byte b)