Java Bit Set setBits(final byte value, final int bitMask, final boolean val)

Here you can find the source of setBits(final byte value, final int bitMask, final boolean val)

Description

set Bits

License

Open Source License

Declaration

public static byte setBits(final byte value, final int bitMask, final boolean val) 

Method Source Code

//package com.java2s;
// and/or modify it under the terms of the GNU General Public License 

public class Main {
    public static byte setBits(final byte value, final int bitMask, final boolean val) {
        byte mask = (byte) (0xFF ^ bitMask);
        byte tmp = (byte) (value & mask);
        if (val) {
            tmp |= bitMask;//w  ww .ja v  a2  s. c o  m
        }
        return tmp;
    }
}

Related

  1. setBitLE(byte[] data, int index)
  2. setBitmapRange(long[] bitmap, int start, int end)
  3. setBitmapRangeAndCardinalityChange(long[] bitmap, int start, int end)
  4. setBitRange(final int val, final int start, final int len, final int newVal)
  5. setBits(byte in, byte data, int position, int fillBits)
  6. setBits(int lowBit, int numBits)
  7. setBits(int value, int bits)
  8. setBits(long value, long bits)
  9. setBitsFromLong(byte[] dst, long dstoff, long l, int off, int len)