Android Int to Byte Array Convert toByteArray(int in, int outSize)

Here you can find the source of toByteArray(int in, int outSize)

Description

to Byte Array

License

LGPL

Declaration

public static byte[] toByteArray(int in, int outSize) 

Method Source Code

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

public class Main {
    public static byte[] toByteArray(int in) {
        byte[] out = new byte[4];

        out[0] = (byte) in;
        out[1] = (byte) (in >> 8);
        out[2] = (byte) (in >> 16);
        out[3] = (byte) (in >> 24);

        return out;
    }/*w ww . j av  a 2 s  . c  om*/

    public static byte[] toByteArray(int in, int outSize) {
        byte[] out = new byte[outSize];
        byte[] intArray = toByteArray(in);
        for (int i = 0; i < intArray.length && i < outSize; i++) {
            out[i] = intArray[i];
        }
        return out;
    }
}

Related

  1. IntToBytes(int value)
  2. intToBytes(byte[] bytes, int offset, int value)
  3. intToBytes(int number)
  4. intToBytes(int number)
  5. toByteArray(int in)
  6. getTwoBytes(int i)
  7. getTwoBytes(int i, byte[] target, int pos)
  8. getFourBytes(int i)
  9. getFourBytes(int i, byte[] target, int pos)