ConvertDataTypes.comConvert data types programming in one click !

Convert byte[] to long in Java

    7526 hits
  • byte[] vInt = new byte[] {
  • (byte)(9223372036854775807L >>> 56),
  • (byte)(9223372036854775807L >>> 48),
  • (byte)(9223372036854775807L >>> 40),
  • (byte)(9223372036854775807L >>> 32),
  • (byte)(9223372036854775807L >>> 24),
  • (byte)(9223372036854775807L >>> 16),
  • (byte)(9223372036854775807L >>> 8),
  • (byte)9223372036854775807L};
  • long vOut = (vInt[0] << 56)
  • + ((vInt[1] & 0xFF) << 48)
  • + ((vInt[2] & 0xFF) << 40)
  • + ((vInt[3] & 0xFF) << 32)
  • + ((vInt[4] & 0xFF) << 24)
  • + ((vInt[5] & 0xFF) << 16)
  • + ((vInt[6] & 0xFF) << 8)
  • + (vInt[7] & 0xFF);