Java Unsigned Number Create unsignedInt2ByteLE(byte[] bytes, long value, int offset)

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

Description

unsigned Int Byte LE

License

Apache License

Declaration

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

Method Source Code

//package com.java2s;
/*// w w  w.j  av a  2 s. c om
 * 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 unsignedInt2ByteLE(byte[] bytes, long 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. unsignedExtend(String hex)
  2. unsignedHalfwordToString(int value)
  3. unsignedInt(byte b)
  4. unsignedInt(int i)
  5. unsignedInt(int value)
  6. unsignedInt2Long(int x)
  7. unsignedInt32ToBytes(long v)
  8. unsignedIntArray2signedIntArray(int[] myIntArray, int numberOfBytes)
  9. unsignedIntersect2by2(final short[] set1, final int length1, final short[] set2, final int length2, final short[] buffer)