Java Integer to Byte intToByte4(int number)

Here you can find the source of intToByte4(int number)

Description

Method converting int into byte array.

License

Open Source License

Parameter

Parameter Description
number The int value to be converted.

Declaration

public static byte[] intToByte4(int number) 

Method Source Code

//package com.java2s;

public class Main {
    /**//from  w w w.ja v a  2  s.  co  m
    *
    * Method converting int into byte array.
    *
    * @param number The int value to be converted.
    *
    */
    public static byte[] intToByte4(int number) {
        int tmp_num = number;
        byte[] byte4 = new byte[4];

        for (int i = byte4.length - 1; i > -1; i--) {
            byte4[i] = (byte) (tmp_num & 0xff);
            tmp_num = tmp_num >> 8;
        }

        return byte4;
    }
}

Related

  1. intToByte(int number, int byteLength)
  2. intToByte(int v, byte[] dest)
  3. intToByte(int value)
  4. intToByte(int value)
  5. intToByte(int[] values)
  6. intToByteArr(int v)