Here you can find the source of setLong(byte[] bytes, int start, int end, long value, ByteOrder byteOrder)
Parameter | Description |
---|---|
bytes | the byte array |
start | starting index position inside byte array |
end | ending position inside byte array |
value | the value |
byteOrder | byte order |
public static byte[] setLong(byte[] bytes, int start, int end, long value, ByteOrder byteOrder)
//package com.java2s; /******************************************************************************* * Copyright 2015 alladin-IT GmbH// ww w.j a v a2s .c om * * 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. *******************************************************************************/ import java.nio.ByteOrder; public class Main { /** * set a long value in a byte array * @param bytes the byte array * @param start starting index position inside byte array * @param end ending position inside byte array * @param value the value * @param byteOrder byte order * @return */ public static byte[] setLong(byte[] bytes, int start, int end, long value, ByteOrder byteOrder) { for (int n = 0; n <= (end - start); n++) { byte b = (byte) (value % 256); bytes[ByteOrder.BIG_ENDIAN.equals(byteOrder) ? (end - start) - (n - start) : n + start] = b; value >>= 8; } return bytes; } }