Java Integer to Byte Array IntToBytes4(int i)

Here you can find the source of IntToBytes4(int i)

Description

Int To Bytes

License

Apache License

Declaration

public static byte[] IntToBytes4(int i) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    public static byte[] IntToBytes4(int i) {
        byte abyte0[] = new byte[4];
        abyte0[3] = (byte) (0xff & i);
        abyte0[2] = (byte) ((0xff00 & i) >> 8);
        abyte0[1] = (byte) ((0xff0000 & i) >> 16);
        abyte0[0] = (byte) ((0xff000000 & i) >> 24);
        return abyte0;
    }/*  ww w  .  jav a 2 s.  c  o  m*/

    public static void IntToBytes4(int i, byte abyte0[]) {
        abyte0[3] = (byte) (0xff & i);
        abyte0[2] = (byte) ((0xff00 & i) >> 8);
        abyte0[1] = (byte) ((0xff0000 & i) >> 16);
        abyte0[0] = (byte) (int) ((0xffffffffff000000L & (long) i) >> 24);
    }
}

Related

  1. intToBytes(int value)
  2. intToBytes(int value, byte[] array, int offset)
  3. intToBytes(int value, byte[] buffer, int offset)
  4. intToBytes(int value, byte[] buffer, int offset, int length, boolean littleEndian)
  5. intToBytes16(int sample, byte[] buffer, int byteOffset, boolean bigEndian)
  6. intToBytesBE(int value, byte[] buffer)
  7. intToBytesBigend(int value)
  8. intToBytesBigEndian(int n)
  9. IntToBytesLE(final long val)