Java Integer to Byte Array int2bytes(int v)

Here you can find the source of int2bytes(int v)

Description

to byte array.

License

Apache License

Parameter

Parameter Description
v value.

Return

byte[].

Declaration

public static byte[] int2bytes(int v) 

Method Source Code

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

public class Main {
    /**//from ww  w  .  j  a v  a  2 s .co  m
     * to byte array.
     * 
     * @param v value.
     * @return byte[].
     */
    public static byte[] int2bytes(int v) {
        byte[] ret = { 0, 0, 0, 0 };
        int2bytes(v, ret);
        return ret;
    }

    /**
     * to byte array.
     * 
     * @param v value.
     * @param b byte array.
     */
    public static void int2bytes(int v, byte[] b) {
        int2bytes(v, b, 0);
    }

    /**
     * to byte array.
     * 
     * @param v value.
     * @param b byte array.
     * @param off array offset.
     */
    public static void int2bytes(int v, byte[] b, int off) {
        b[off + 3] = (byte) v;
        b[off + 2] = (byte) (v >>> 8);
        b[off + 1] = (byte) (v >>> 16);
        b[off + 0] = (byte) (v >>> 24);
    }
}

Related

  1. int2Bytes(int num)
  2. int2bytes(int num)
  3. int2Bytes(int num)
  4. int2bytes(int num)
  5. int2bytes(int num, int len)
  6. int2bytes(int val, byte[] bytes, int offset, boolean bigEndian)
  7. int2bytes(int value)
  8. int2bytes(int value)
  9. int2Bytes(int value)