Java Byte Array Create toByteArray(int in, int size)

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

Description

to Byte Array

License

Open Source License

Declaration

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

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] toByteArray(int in, int size) {
        byte[] bytes = new byte[size];

        for (int i = size - 1; i >= 0; i--) {
            bytes[(size - 1) - i] = (byte) (in >>> 8 * i);
        }//from  ww w.  ja  va2 s  .  co m

        return bytes;
    }

    public static byte[] toByteArray(int value) {
        return new byte[] { (byte) (value >>> 24), (byte) (value >>> 16), (byte) (value >>> 8), (byte) value };
    }
}

Related

  1. toByteArray(final String bitString)
  2. toByteArray(final String hexString)
  3. toByteArray(int data)
  4. toByteArray(int i)
  5. toByteArray(int in)
  6. toByteArray(int intr)
  7. toByteArray(int num)
  8. toByteArray(int value)
  9. toByteArray(int value)