Java Integer to Byte Array intToBytes(int ipInt)

Here you can find the source of intToBytes(int ipInt)

Description

ipInt -> byte[]

License

Open Source License

Parameter

Parameter Description
ipInt a parameter

Return

byte[]

Declaration

public static byte[] intToBytes(int ipInt) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    private final static int INADDRSZ = 4;

    /**/*w w w.j av a 2  s .c  om*/
     * ipInt -> byte[]
     *
     * @param ipInt
     * @return byte[]
     */
    public static byte[] intToBytes(int ipInt) {
        byte[] ipAddr = new byte[INADDRSZ];
        ipAddr[0] = (byte) ((ipInt >>> 24) & 0xFF);
        ipAddr[1] = (byte) ((ipInt >>> 16) & 0xFF);
        ipAddr[2] = (byte) ((ipInt >>> 8) & 0xFF);
        ipAddr[3] = (byte) (ipInt & 0xFF);
        return ipAddr;
    }
}

Related

  1. IntToBytes(int i)
  2. intToBytes(int i)
  3. intToBytes(int i, byte[] data, int[] offset)
  4. intToBytes(int i_)
  5. intToBytes(int intValue)
  6. intToBytes(int n)
  7. intToBytes(int n)
  8. intToBytes(int num, byte[] arr, int pos)
  9. intToBytes(int num, byte[] bytes, int startIndex)