fork(2) download
  1. class Ideone {
  2. public static byte[] getBytes(int value) {
  3. int i = 4;
  4. byte[] res = new byte[i];
  5. while (i-- > 0) {
  6. res[i] = (byte)(value & 0xFF);
  7. value >>= 8;
  8. }
  9. return res;
  10. }
  11.  
  12. public static int getInt(byte[] value) {
  13. int res = 0;
  14. for (int i = 0; i < 4; ++i) {
  15. res = (res << 8) | value[i] & 0xFF;
  16. }
  17. return res;
  18. }
  19.  
  20. public static void printBytes(byte[] value) {
  21. for (byte it : value) {
  22. System.out.printf("%02X ", it);
  23. }
  24. }
  25.  
  26. public static void main (String[] args) throws java.lang.Exception {
  27. byte[] a = getBytes(123456789);
  28. printBytes(a);
  29. System.out.println(" = " + getInt(a));
  30. }
  31. }
Success #stdin #stdout 0.1s 320320KB
stdin
Standard input is empty
stdout
07 5B CD 15  = 123456789