Java Byte Array Create byteArrayFromInteger(int integer)

Here you can find the source of byteArrayFromInteger(int integer)

Description

Convert an integer value into the corresponding byte array

License

Open Source License

Parameter

Parameter Description
integer The integer to convert

Return

The byte array representing the given integer

Declaration

public static byte[] byteArrayFromInteger(int integer) 

Method Source Code

//package com.java2s;
/**//from w w  w .  jav  a 2  s  .  c  om
 * This code is free software; you can redistribute it and/or modify it under
 * the terms of the new BSD License.
 *
 * Copyright (c) 2008-2011, Sebastian Staudt
 */

public class Main {
    /**
     * Convert an integer value into the corresponding byte array
     *
     * @param integer The integer to convert
     * @return The byte array representing the given integer
     */
    public static byte[] byteArrayFromInteger(int integer) {
        return new byte[] { (byte) (integer >> 24), (byte) (integer >> 16),
                (byte) (integer >> 8), (byte) integer };
    }
}

Related

  1. byteArrayFromBytes(int... bytes)
  2. byteArrayFromChar(char i)
  3. byteArrayFromHexString(String in)
  4. byteArrayFromInt(final int number)
  5. byteArrayFromInteger(int integer)
  6. bytes(final byte... elements)
  7. bytes(final int... ints)
  8. bytes(int... bytes)