Java Byte Array to Long bytesToLong(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte h, boolean swapBytes)

Here you can find the source of bytesToLong(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte h, boolean swapBytes)

Description

Concatenate eight bytes to a 64-bit int value.

License

Open Source License

Parameter

Parameter Description
a highest order byte
b second-highest order byte
c next order byte
d next order byte
e next order byte
f next order byte
g next order byte
h lowest order byte
swapBytes byte order swap flag

Return

64-bit long see edu.iris.Fissures.seed.util.Utility#uBytesToLong(byte,byte,byte,byte,boolean)

Declaration

public static long bytesToLong(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte h,
        boolean swapBytes) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  w w  . ja  v a  2s .  c o  m
     * Concatenate eight bytes to a 64-bit int value.  Byte order is <b>a,b,c,d,e,f,g,h</b>
     * unless swapBytes is true, in which case the order is <b>h,g,f,e,d,c,b,a</b>.
     * <i>Note:</i> This method will accept unsigned and signed byte
     * representations, since high bit extension is not a concern here.
     * Java does not support unsigned long integers, so the maximum value is not as
     * high as would be the case with an unsigned integer.  
     * @param a highest order byte
     * @param b second-highest order byte
     * @param c next order byte
     * @param d next order byte
     * @param e next order byte
     * @param f next order byte
     * @param g next order byte
     * @param h lowest order byte
     * @param swapBytes byte order swap flag
     * @return 64-bit long
     * see edu.iris.Fissures.seed.util.Utility#uBytesToLong(byte,byte,byte,byte,boolean)
     */
    public static long bytesToLong(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte h,
            boolean swapBytes) {
        if (swapBytes) {
            return ((a & 0xffl)) + ((b & 0xffl) << 8) + ((c & 0xffl) << 16) + ((d & 0xffl) << 24)
                    + ((e & 0xffl) << 32) + ((f & 0xffl) << 40) + ((g & 0xffl) << 48) + ((h & 0xffl) << 56);
        } else {
            return ((a & 0xffl) << 56) + ((b & 0xffl) << 48) + ((c & 0xffl) << 40) + ((d & 0xffl) << 32)
                    + ((e & 0xffl) << 24) + ((f & 0xffl) << 16) + ((g & 0xffl) << 8) + ((h & 0xffl));
        }
    }
}

Related

  1. bytes2long(byte[] bytes, boolean bigEndian)
  2. bytes2Long(byte[] bytes, int offset)
  3. bytes2Long(final byte[] b)
  4. bytes2long(final byte[] bytes, final int start)
  5. bytesToLong(byte a, byte b, byte c, byte d)
  6. bytesToLong(byte[] a, int ao)
  7. bytesToLong(byte[] arr, int offset)
  8. bytesToLong(byte[] array, int offset)
  9. bytesToLong(byte[] b)