Java Bit Set setBit(byte a, int pos, boolean set)

Here you can find the source of setBit(byte a, int pos, boolean set)

Description

set byte a's pos'th bit

License

Apache License

Parameter

Parameter Description
a a parameter
pos a parameter
set a parameter

Declaration

public static void setBit(byte a, int pos, boolean set) 

Method Source Code

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

public class Main {
    /**/* w w  w . java2  s .  c  om*/
     * set byte a's pos'th bit
     * @param a
     * @param pos
     * @param set
     */
    public static void setBit(byte a, int pos, boolean set) {
        if (true == set) {
            a = (byte) (a | (1 << pos));
        } else {
            a = (byte) (a & ~(1 << pos));
        }
    }
}

Related

  1. SetBit(byte _bitset, byte bit)
  2. setBit(byte _byte, int position, boolean value)
  3. setBit(byte b, int i)
  4. setBit(byte b, int pos)
  5. setBit(byte data, byte bit, boolean value)
  6. setBit(byte data, int bitNumber, boolean value)