Here you can find the source of getBit(ByteBuffer in, int pos)
Parameter | Description |
---|---|
in | The input ByteBuffer |
pos | The bit position in the given ByteBuffer |
public static final int getBit(ByteBuffer in, int pos)
//package com.java2s; /******************************************************************************* * Copyright (c) 2011 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors://w w w .j ava 2s .co m * IBM Corporation - Initial API and implementation *******************************************************************************/ import java.nio.ByteBuffer; public class Main { /** A constant equal to the number of bits per byte */ public static final int NBITS_PER_BYTE = 8; /** * Get a bit from the input ByteBuffer * * Returns the bit at bit position pos in ByteBuffer in. * * @param in * The input ByteBuffer * @param pos * The bit position in the given ByteBuffer * @return Returns non-zero if the bit is set otherwise return zero. */ public static final int getBit(ByteBuffer in, int pos) { return in.get(pos >> 3) & (1 << (pos % NBITS_PER_BYTE)); } }