Java ByteBuffer to Short Array getShortBE(ByteBuffer b, int start, int end)

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

Description

get Short BE

License

Open Source License

Declaration

public static short getShortBE(ByteBuffer b, int start, int end) 

Method Source Code

//package com.java2s;
/*//w w  w  .j  a v a2 s  . co  m
 * Entagged Audio Tag library
 * Copyright (c) 2003-2005 Rapha?l Slinckx <raphael@slinckx.net>
 * 
 * This library 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 2.1 of the License, or (at your option) any later version.
 *  
 * This library 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 this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */

import java.nio.ByteBuffer;

public class Main {
    public static short getShortBE(ByteBuffer b, int start, int end) {
        return (short) getIntBE(b, start, end);
    }

    public static int getIntBE(byte[] b, int start, int end) {
        return (int) getLongBE(ByteBuffer.wrap(b), start, end);
    }

    public static int getIntBE(ByteBuffer b, int start, int end) {
        return (int) getLongBE(b, start, end);
    }

    public static long getLongBE(ByteBuffer b, int start, int end) {
        int number = 0;
        for (int i = 0; i < (end - start + 1); i++) {
            number += ((b.get(end - i) & 0xFF) << i * 8);
        }

        return number;
    }
}

Related

  1. getShort(ByteBuffer b, int n)
  2. getShort(ByteBuffer bb)
  3. getShort(ByteBuffer buffer)
  4. getShort(ByteBuffer byteBuffer)
  5. getShortB(ByteBuffer bb, int bi)
  6. getShortBE(final ByteBuffer b, final int start, final int end)
  7. getShortLength(ByteBuffer bb)
  8. getShortLength(ByteBuffer bb, int position)
  9. getShortNumeric(java.nio.ByteBuffer buffer, int len)