Java BCD Convert To bcdToLong(byte[] src, int flag)

Here you can find the source of bcdToLong(byte[] src, int flag)

Description

bcd To Long

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {

    public static long bcdToLong(byte[] src, int flag) {
        byte high, low;
        long re = 0;

        if (flag == 0) {
            for (int i = 0; i < src.length; i++) {
                re *= 256;/*from w ww  . ja  v a  2  s .co  m*/
                high = (byte) (src[i] >> 4 & 0x0f);
                low = (byte) (src[i] & 0x0f);
                re += Long.valueOf(high) * 16 + Long.valueOf(low);
            }
        } else {
            for (int i = 0; i < src.length; i++) {
                re *= 100;
                high = (byte) (src[i] >> 4 & 0x0f);
                low = (byte) (src[i] & 0x0f);
                re += Long.valueOf(high) * 10 + Long.valueOf(low);
            }
        }
        return re;
    }
}

Related

  1. bcd2String(byte[] bytes)
  2. bcdNibbleToInt(byte b, boolean high)
  3. bcdToByte(byte src)
  4. BCDtoInt(int bcd)
  5. BCDToLong(byte[] bcdByte)
  6. bcdToString(byte[] bcd)