Java Integer to Byte Array intToBytes(int value, byte[] array, int offset)

Here you can find the source of intToBytes(int value, byte[] array, int offset)

Description

Marshal an integer to a byte array.

License

Open Source License

Parameter

Parameter Description
array The array of bytes.
offset The offset from which to start marshalling.

Declaration

public static void intToBytes(int value, byte[] array, int offset) 

Method Source Code

//package com.java2s;
/*//w  w w  . j  av a 2s  . c o  m
 * %W% %E%
 *
 * Copyright (c) 2006, Oracle and/or its affiliates. All rights reserved.
 * ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

public class Main {
    /** Marshal an integer to a byte array.
        The bytes are in BIGENDIAN order.
        i.e. array[offset] is the most-significant-byte
        and  array[offset+3] is the least-significant-byte.
        @param array The array of bytes.
        @param offset The offset from which to start marshalling.
     */
    public static void intToBytes(int value, byte[] array, int offset) {
        array[offset++] = (byte) ((value >>> 24) & 0xFF);
        array[offset++] = (byte) ((value >>> 16) & 0xFF);
        array[offset++] = (byte) ((value >>> 8) & 0xFF);
        array[offset++] = (byte) ((value >>> 0) & 0xFF);
    }
}

Related

  1. intToBytes(int val, byte[] bytes, int start)
  2. intToBytes(int val, int byteCount)
  3. intToBytes(int value)
  4. intToBytes(int value)
  5. intToBytes(int value)
  6. intToBytes(int value, byte[] buffer, int offset)
  7. intToBytes(int value, byte[] buffer, int offset, int length, boolean littleEndian)
  8. intToBytes16(int sample, byte[] buffer, int byteOffset, boolean bigEndian)
  9. IntToBytes4(int i)