Java Bit Set setBit(byte original, int bitToSet)

Here you can find the source of setBit(byte original, int bitToSet)

Description

Sets a bit to one in a byte then returns new byte

License

Open Source License

Parameter

Parameter Description
original byte
bitToSet bit to set

Return

byte with changed bit

Declaration

public static byte setBit(byte original, int bitToSet) 

Method Source Code

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

public class Main {
    /**/*  ww w .  j  a v a 2 s  .co  m*/
     * Sets a bit to one in a byte then returns new byte
     * @param original byte
     * @param bitToSet bit to set
     *
     * @return byte with changed bit
     */
    public static byte setBit(byte original, int bitToSet) {
        return (byte) (original | (1 << bitToSet));
    }
}

Related

  1. setBit(byte data, int bitNumber, boolean value)
  2. setBit(byte data, int bitPos, boolean on)
  3. setBit(byte data, int pos, int val)
  4. setBit(byte in, int position, boolean value)
  5. setBit(byte input, int bit)
  6. setBit(byte target, byte pos)
  7. setBit(byte v, int position, boolean value)
  8. setBit(byte value, int bit, boolean on)
  9. setBit(byte value, int bit, boolean state)