fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.nio.ByteBuffer;
  7. import java.nio.ByteOrder;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. byte[] b = new byte[4];
  15. // 03 00 00 00
  16. // 00 28 00 00
  17. // AA 64 FE 00
  18. b[0] = (byte)0xaa;
  19. b[1] = (byte)0x64;
  20. b[2] = (byte)0xfe;
  21. b[3] = (byte)0x00;
  22.  
  23. long val = 0;
  24. val += new Byte(b[3]).intValue();
  25. val += new Byte(b[2]).intValue();
  26. val += new Byte(b[1]).intValue();
  27. val += new Byte(b[0]).intValue();
  28.  
  29. //long val = 0l;//ByteBuffer.wrap(b).order(ByteOrder.LITTLE_ENDIAN).getLong();
  30. long l = (long)b[0] & 0xFF;
  31. l += ((long)b[1] & 0xFF) << 8;
  32. l += ((long)b[2] & 0xFF) << 16;
  33. l += ((long)b[3] & 0xFF) << 24;
  34. System.out.println(Long.toHexString(val) + ", " + String.valueOf(l));
  35. }
  36. }
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
c, 16671914