Java Long to longToBcd(long src, int len, int flag)

Here you can find the source of longToBcd(long src, int len, int flag)

Description

long To Bcd

License

Apache License

Declaration

public static byte[] longToBcd(long src, int len, int flag) 

Method Source Code

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

Related

  1. longTo4LengthBytes(long num)
  2. LongToAscii(long number, byte[] buf, int offset, int length)
  3. longToBaseCode(char[] target, int targetOffset, long value, int base, int lengthLimit, boolean fillZeros, boolean upperCase)
  4. longToBasicType(long l, Class clazz)
  5. longToBcd(long num, int size)
  6. longToBigEndian(long value, byte[] in, int offset)
  7. longToBinary(long num)
  8. longtobinarystring(long wert, int bits)
  9. longToBinaryStringUnsigned(long value)