Convert byte array to Long : Data Type cast « Data Type « Java






Convert byte array to Long

   


public class Util {

  public static long toLong(byte[] b) {
    long n = (long) (b[0] & 0xff) << 56 | (long) (b[1] & 0xff) << 48
        | (long) (b[2] & 0xff) << 40 | (long) (b[3] & 0xff) << 32
        | (long) (b[4] & 0xff) << 24 | (long) (b[5] & 0xff) << 16
        | (long) (b[6] & 0xff) << 8 | (long) (b[7] & 0xff);

    return n;
  }
}

   
    
    
  








Related examples in the same category

1.Cast a float or double to an integral valueCast a float or double to an integral value
2.A simple casting demo
3.Casting Demo
4.Get the minimum and maximum value of a primitive data types?
5.Class with methods for type conversion
6.Data type conversion
7.Data type Conversion Util
8.Convert Byte array to Int
9.Convert Number To Target Class
10.Convert long to Bytes
11.Conversion utilities
12.Get Time From Date
13.Get String From Date
14.A method used to build a date for use Marker XML and KML data
15.A method used to build a date for display in line with existing formatting rules