集册 Java实例教程 以整数形式返回8个无符号位。

以整数形式返回8个无符号位。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

418
以整数形式返回8个无符号位。
/* from n o w  j a v a  . c o m*/


import java.io.IOException;

import java.io.InputStream;

import java.nio.ByteBuffer;

import java.util.Iterator;

import org.apache.log4j.Logger;


public class Main{

    /**

     * Returns 8 unsigned bits as an integer.

     * 

     * @param buf

     * @return

     */

    final public static int getUnsignedByte(ByteBuffer buf) {

        return ((int) buf.get()) & 0xff;

    }

}