Java Bit Set setBitAt(int offset, boolean bitValue, byte aByte)

Here you can find the source of setBitAt(int offset, boolean bitValue, byte aByte)

Description

Set a bit within a byte.

License

Apache License

Parameter

Parameter Description
offset The bit offset within the byte.
bitValue The bit value to set.
aByte A byte of bits.

Return

A new byte with the settings applied.

Declaration

public static byte setBitAt(int offset, boolean bitValue, byte aByte) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from www.j a v a2  s .c  o  m
     * Set a bit within a byte.
     * 
     * @param offset The bit offset within the byte.
     * @param bitValue The bit value to set.
     * @param aByte A byte of bits.
     * @return A new byte with the settings applied.
     */
    public static byte setBitAt(int offset, boolean bitValue, byte aByte) {
        return (byte) ((bitValue) ? (aByte | (1 << offset)) : (aByte & ~(1 << offset)));
    }
}

Related

  1. setBit(int[] x, int i, int v)
  2. setBit(long[] data, int position, int bitWidth)
  3. setBit(short shortIn, int bitPos)
  4. setBitAt(byte flags, int pos, boolean value)
  5. setBitAt(int bitIndex, boolean value, byte b)
  6. setBitAt(int offset, boolean bitValue, byte aByte)
  7. setBitBiInt(int b0, int b1, int value, int original)
  8. setBitByPos(byte byt, boolean bool, int pos)
  9. setBitInInt(int bits, int bitIndex, boolean flag)