Here you can find the source of intToBcd(int src, int len, int flag)
public static byte[] intToBcd(int src, int len, int flag)
//package com.java2s; //License from project: Apache License public class Main { public static byte[] intToBcd(int src, int len, int flag) { return longToBcd(src, len, flag); }/*from w w w . j a va 2 s.c o m*/ public static byte[] longToBcd(long src, int len, int flag) { byte[] re = new byte[len]; long tmp, high, low; if (src < 0) throw new RuntimeException(String.format("number: [%d] convert bcd error", src)); for (int i = len - 1; i >= 0; i--) { if (src == 0) break; if (flag == 1) { tmp = src % 100; src /= 100; high = tmp / 10; low = tmp % 10; } else { tmp = src % 256; src /= 256; high = tmp / 16; low = tmp % 16; } re[i] = (byte) (high << 4 ^ low); } return re; } }