Convert int to int array of the byte data


/ Published in: Java
Save to your folder(s)

in Java an int is 4 bytes (32 bits)


Copy this code and paste it in your HTML
  1. int[] getIntBytesFromInt(int base) {
  2. int[] nums = new int[4];
  3. nums[0] = base & 0x000000FF;
  4. nums[1] = (base>>>8) & 0x000000FF;
  5. nums[2] = (base>>>16) & 0x000000FF;
  6. nums[3] = (base>>>24) & 0x000000FF;
  7. return nums;
  8. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.