Java Byte Array Create toBytes(long l, byte[] bytes, int offset, int limit)

Here you can find the source of toBytes(long l, byte[] bytes, int offset, int limit)

Description

Converts primitive long type to byte array and stores it in specified byte array.

License

GNU General Public License

Parameter

Parameter Description
l Unsigned long value.
bytes Bytes array to write result to.
offset Offset in the target array to write result to.
limit Limit of bytes to write into output.

Return

Number of bytes overwritten in bytes array.

Declaration

private static byte[] toBytes(long l, byte[] bytes, int offset, int limit) 

Method Source Code

//package com.java2s;
// Copyright (C) GridGain Systems Licensed under GPLv3, http://www.gnu.org/licenses/gpl.html

public class Main {
    /**/*from  www  .  j  a  v a2s  . c om*/
     * Converts primitive {@code long} type to byte array and stores it in specified
     * byte array. The highest byte in the value is the first byte in result array.
     *
     * @param l Unsigned long value.
     * @param bytes Bytes array to write result to.
     * @param offset Offset in the target array to write result to.
     * @param limit Limit of bytes to write into output.
     * @return Number of bytes overwritten in {@code bytes} array.
     */
    private static byte[] toBytes(long l, byte[] bytes, int offset, int limit) {
        assert bytes != null;
        assert limit <= 8;
        assert bytes.length >= offset + limit;

        for (int i = limit - 1; i >= 0; i--) {
            bytes[offset + i] = (byte) (l & 0xFF);
            l >>>= 8;
        }

        return bytes;
    }
}

Related

  1. toBytes(int value, byte[] dest, int destPos)
  2. toBytes(int x, byte[] out)
  3. toBytes(int[] ints)
  4. toBytes(long input)
  5. toBytes(long l)
  6. toBytes(long lp)
  7. toBytes(long n)
  8. toBytes(long number)
  9. toBytes(long size)