Java Integer to Byte intTo4Byte(int i)

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

Description

int To Byte

License

GNU General Public License

Declaration

public static byte[] intTo4Byte(int i) 

Method Source Code

//package com.java2s;
/**// ww  w . ja v  a  2  s .c  om
 * License
 * 
 * Licensed under the GNU GPL v3
 * http://www.gnu.org/licenses/gpl.html
 * 
 */

public class Main {
    public static byte[] intTo4Byte(int i) {
        return numberToByte(i, 4);
    }

    private static byte[] numberToByte(long l, int length) {
        byte[] bts = new byte[length];
        for (int i = 0; i < length; i++) {
            bts[i] = (byte) (l >> ((length - i - 1) * 8));
        }
        return bts;
    }
}

Related

  1. int2ByteArrayLength4(int theInt)
  2. int2ToByteArray(int value)
  3. int2ubyte(int in)
  4. intAsByte(int value)
  5. intTo1Byte(int x)
  6. intToByte(byte[] buf, int off, int value)
  7. intToByte(final int i)
  8. intToByte(int i)
  9. IntToByte(int i)