Java Integer Convert To fromInt(int input)

Here you can find the source of fromInt(int input)

Description

Returns a byte array containing 4 network byte-ordered bytes representing the given int .

License

BSD License

Parameter

Parameter Description
input An int to convert to a byte array.

Return

A byte array representation of an int in network byte order (i.e., big-endian order).

Declaration

public static byte[] fromInt(int input) 

Method Source Code

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

public class Main {
    /**//from  www  .  j av  a2 s.  co m
     * Returns a byte array containing 4 network byte-ordered bytes representing the
     * given {@code int}.
     *
     * @param input An {@code int} to convert to a byte array.
     * @return A byte array representation of an {@code int} in network byte order
     * (i.e., big-endian order).
     */
    public static byte[] fromInt(int input) {
        byte[] output = new byte[4];
        output[0] = (byte) (input >> 24);
        output[1] = (byte) (input >> 16);
        output[2] = (byte) (input >> 8);
        output[3] = (byte) input;
        return output;
    }
}

Related

  1. fromInt(byte[] buffer, int pos, int i)
  2. fromInt(final int value, final int length)
  3. fromInt(int i)
  4. fromint(int i)
  5. fromInt(int input)
  6. fromInt(int intValue)
  7. fromInt(int key)
  8. fromInt(int value)
  9. fromInt(int value)