Here you can find the source of getIntBE(final ByteBuffer b, final int start, final int end)
Parameter | Description |
---|---|
b | The ByteBuffer |
start | The starting offset in b. The less significant byte |
end | The end index (included) in b |
public static int getIntBE(final ByteBuffer b, final int start, final int end)
//package com.java2s; /*/* w ww .java2 s . c om*/ * 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 most significant and the last * byte is the least significant. * * @param b The ByteBuffer * @param start The starting offset in b. The less significant byte * @param end The end index (included) in b * * @return an int number represented by the byte sequence. */ public static int getIntBE(final ByteBuffer b, final int start, final int end) { return (int) getLongBE(b, start, end); } /** * Computes a number whereby the 1st byte is the most significant and the last * byte is the least significant. * <p> * So if storing a number which only requires one byte it will be stored in the last * byte. * <p> * Will fail if end - start >= 8, due to the limitations of the long type. */ public static long getLongBE(final ByteBuffer b, final int start, final int end) { long number = 0; for (int i = 0; i < (end - start + 1); i++) { number += ((long) ((b.get(end - i) & 0xFF)) << i * 8); } return number; } }