Java ByteBuffer Put setBit(ByteBuffer input, int pos)

Here you can find the source of setBit(ByteBuffer input, int pos)

Description

Sets the bit in given input to one Sets the pos bit in input to one

License

Open Source License

Parameter

Parameter Description
input The input ByteBuffer
pos The position in the input ByteBuffer to set.

Declaration


public static final void setBit(ByteBuffer input, int pos) 

Method Source Code

//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 .ja v a 2s  . com*/
 *     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;

    /**
     * Sets the bit in given input to one
     * 
     * Sets the pos bit in input to one
     * 
     * @param input
     *            The input ByteBuffer
     * @param pos
     *            The position in the input ByteBuffer to set.
     */

    public static final void setBit(ByteBuffer input, int pos) {
        input.put(pos >> 3, (byte) (input.get(pos >> 3) | (1 << (pos % NBITS_PER_BYTE))));
    }
}

Related

  1. readNextLine(InputStream in, ByteBuffer buff, boolean acceptEOF, boolean requireCR)
  2. readPackedLong(ByteBuffer input)
  3. readToByteBuffer(InputStream inStream)
  4. serializeNullableString(ByteBuffer outputBuffer, String value)
  5. serializeObject(Object obj, ByteBuffer buffer, ByteArrayOutputStream baos, boolean markEndOfHeader)
  6. skipBlank(ByteBuffer input)
  7. toByteArrayInputStream(ByteBuffer buffer)
  8. toByteBuffer(InputStream inputStream)
  9. toByteBuffer(String input)