Java ByteBuffer to Long Array getLongLE(final ByteBuffer b, final int start, final int end)

Here you can find the source of getLongLE(final ByteBuffer b, final int start, final int end)

Description

Computes a number whereby the 1st byte is the least significant and the last byte is the most significant.

License

Open Source License

Parameter

Parameter Description
b The byte array @param start The starting offset in b (b[offset]). The less significant byte @param end The end index (included) in b (b[end]). The most significant byte

Return

a long number represented by the byte sequence.

Declaration

public static long getLongLE(final ByteBuffer b, final int start, final int end) 

Method Source Code

//package com.java2s;
/*//from  w  w  w  .j a  va2 s  . c o m
 * Copyright (c) 2017 Eric A. Snell
 *
 * This file is part of eAlvaTag.
 *
 * eAlvaTag is free software: you can redistribute it and/or modify it under the terms of the GNU Lesser
 * General Public License as published by the Free Software Foundation, either version 3 of the License,
 * or (at your option) any later version.
 *
 * eAlvaTag is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
 * the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with eAlvaTag.  If not,
 * see <http://www.gnu.org/licenses/>.
 */

import java.nio.ByteBuffer;

public class Main {
    /**
     * Computes a number whereby the 1st byte is the least significant and the last
     * byte is the most significant.
     * So if storing a number which only requires one byte it will be stored in the first
     * byte.
     *
     * @param b The byte array @param start The starting offset in b (b[offset]). The less significant byte @param end The end index
     *          (included) in b (b[end]). The most significant byte
     *
     * @return a long number represented by the byte sequence.
     */
    public static long getLongLE(final ByteBuffer b, final int start, final int end) {
        long number = 0;
        for (int i = 0; i < (end - start + 1); i++) {
            number += ((b.get(start + i) & 0xFF) << i * 8);
        }

        return number;
    }
}

Related

  1. getLongB(ByteBuffer bb, int index)
  2. getLongBE(ByteBuffer b, int start, int end)
  3. getLongByteBuffer(long id)
  4. getLongFromBuffer(ByteBuffer buffer, int offset, int size)
  5. getLongFromByteBuffer(ByteBuffer data)
  6. getLongWithChecksum(ByteBuffer buffer, Adler32 checksum)