Here you can find the source of longToBcd(long src, int len, int flag)
public static byte[] longToBcd(long src, int len, int flag)
//package com.java2s; //License from project: Apache License public class Main { 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;//from w w w . j a v a 2 s .c om 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; } }