Java Integer to Byte Array int2ByteLE(byte[] bytes, int value, int offset)

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

Description

int Byte LE

License

Apache License

Declaration

public static void int2ByteLE(byte[] bytes, int value, int offset) 

Method Source Code

//package com.java2s;
/*/*from w ww. ja v  a2  s.  c o  m*/
 * Copyright 2015-2017 GenerallyCloud.com
 *  
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *  
 *      http://www.apache.org/licenses/LICENSE-2.0
 *  
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    public static void int2ByteLE(byte[] bytes, int value, int offset) {

        checkLength(bytes, 4, offset);

        bytes[offset + 0] = (byte) ((value & 0xff));
        bytes[offset + 1] = (byte) ((value >> 8 * 1) & 0xff);
        bytes[offset + 2] = (byte) ((value >> 8 * 2) & 0xff);
        bytes[offset + 3] = (byte) ((value >> 8 * 3));
    }

    private static void checkLength(byte[] bytes, int length, int offset) {

        if (bytes == null) {
            throw new IllegalArgumentException("null");
        }

        if (offset < 0) {
            throw new IllegalArgumentException("invalidate offset " + offset);
        }

        if (bytes.length - offset < length) {
            throw new IllegalArgumentException("invalidate length " + bytes.length);
        }
    }
}

Related

  1. convertIntToByteArray(int[] rgb)
  2. convertIntToBytes(int i)
  3. fromIntToByte(int integer)
  4. fromIntToByteArray(int value)
  5. int2Arr(int var, byte[] arrayBytes, int startIndex)
  6. int2bytes(int i)
  7. int2Bytes(int i, byte[] bytes, int offset)
  8. int2bytes(int integer)
  9. int2bytes(int intValue)