List of utility methods to do BCD Convert To
String | BCD2ASC(byte[] bytes) BCDASC char[] BToA = "0123456789abcdef".toCharArray(); StringBuffer temp = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { int h = ((bytes[i] & 0xf0) >>> 4); int l = (bytes[i] & 0x0f); temp.append(BToA[h]).append(BToA[l]); return temp.toString(); ... |
byte[] | bcd2Ascii(byte[] bytes) bcd Ascii byte[] temp = new byte[bytes.length * 2]; for (int i = 0; i < bytes.length; i++) { temp[i * 2] = (byte) ((bytes[i] >> 4) & 0x0f); temp[i * 2 + 1] = (byte) (bytes[i] & 0x0f); return temp; |
String | bcd2str(byte[] b) bcdstr StringBuffer sb = new StringBuffer(); for (int i = 0; i < b.length; ++i) { int h = ((b[i] & 255) >> 4) + 48; sb.append((char) h); int l = (b[i] & 15) + 48; sb.append((char) l); return sb.toString(); ... |
String | bcd2str(byte[] b, int offset, int len, boolean padLeft) converts a BCD representation of a number to a String StringBuilder d = new StringBuilder(len); int start = (((len & 1) == 1) && padLeft) ? 1 : 0; for (int i = start; i < len + start; i++) { int shift = ((i & 1) == 1 ? 0 : 4); char c = Character.forDigit(((b[offset + (i >> 1)] >> shift) & 0x0F), 16); if (c == 'd') c = '='; d.append(Character.toUpperCase(c)); ... |
String | bcd2Str(byte[] bytes) bcd Str StringBuffer temp = new StringBuffer(bytes.length * 2); for (int i = 0; i < bytes.length; i++) { temp.append((byte) ((bytes[i] & 0xF0) >>> 4)); temp.append((byte) (bytes[i] & 0xF)); return temp.toString().substring(0, 1).equalsIgnoreCase("0") ? temp.toString().substring(1) : temp.toString(); |
String | bcd2String(byte[] bytes) bcd String char temp[] = new char[bytes.length * 2], val; for (int i = 0; i < bytes.length; i++) { val = (char) (((bytes[i] & 0xf0) >> 4) & 0x0f); temp[i * 2] = (char) (val > 9 ? val + 'A' - 10 : val + '0'); val = (char) (bytes[i] & 0x0f); temp[i * 2 + 1] = (char) (val > 9 ? val + 'A' - 10 : val + '0'); return new String(temp); ... |
int | bcdNibbleToInt(byte b, boolean high) bcd Nibble To Int int n; if (high) n = (b >> 4) & 0xf; else n = b & 0xf; if (n > 9) n = 0; return n; ... |
byte | bcdToByte(byte src) bcd To Byte byte re = src; if (src <= 0x09 && src >= 0x00) re = (byte) (src + 0x30); else if (src <= 0x0f && src >= 0x0a) re = (byte) (src + 0x37); return re; |
int | BCDtoInt(int bcd) BC Dto Int return (bcd / 16 * 10 + bcd % 16);
|
long | BCDToLong(byte[] bcdByte) BCD To Long if (bcdByte == null) return Integer.MIN_VALUE; return BCDToLong(bcdByte, 0, bcdByte.length); |