Java Bit Set setBit(byte value, int bit, boolean state)

Here you can find the source of setBit(byte value, int bit, boolean state)

Description

Sets the given bit in the given value.

License

Open Source License

Parameter

Parameter Description
value Value to change.
bit Bit to change.
state New value of the bit.

Return

The resulting value.

Declaration

public static byte setBit(byte value, int bit, boolean state) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    /**//from  w  ww  .  j  a  v  a  2s.c  o  m
     * Sets the given bit in the given value.
     * @param value Value to change.
     * @param bit Bit to change.
     * @param state New value of the bit.
     * @return The resulting value.
     */
    public static byte setBit(byte value, int bit, boolean state) {
        return state ? (byte) (value | bit) : (byte) (value & ~bit);
    }
}

Related

  1. setBit(byte original, int bitToSet)
  2. setBit(byte target, byte pos)
  3. setBit(byte v, int position, boolean value)
  4. setBit(byte value, int bit, boolean on)
  5. setBit(byte value, int bit, boolean state)
  6. setBit(byte[] arr, int bit)
  7. setBit(byte[] b, int index)
  8. setBit(byte[] ba, int bit_offset, boolean on)
  9. setBit(byte[] byteArray, int index)