Java Bit Set setBit(final byte input, final int bit, final boolean status)

Here you can find the source of setBit(final byte input, final int bit, final boolean status)

Description

set Bit

License

Open Source License

Declaration

public static byte setBit(final byte input, final int bit, final boolean status) 

Method Source Code

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

public class Main {
    public static byte setBit(final byte input, final int bit, final boolean status) {
        if (status)
            return (byte) (input | 1 << bit);
        else// w  ww  .  java 2s. com
            return (byte) (input & ~(1 << bit));
    }

    public static short setBit(final short input, final int bit, final boolean status) {
        if (status)
            return (short) (input | 1 << bit);
        else
            return (short) (input & ~(1 << bit));
    }

    public static int setBit(final int input, final int bit, final boolean status) {
        if (status)
            return (short) (input | 1 << bit);
        else
            return (short) (input & ~(1 << bit));
    }
}

Related

  1. setBit(byte[] data, int index, boolean value)
  2. setBit(byte[] data, int pos, boolean val)
  3. setBit(byte[] data, int pos, int val)
  4. setBit(byte[] data, int pos, int val)
  5. setBit(byte[] data, long pos, byte val)
  6. setBit(final byte pData, final int pBitIndex, final boolean pOn)
  7. setBit(final byte[] buf, final long bitIndex, final boolean value)
  8. setbit(final int num, final int bitnum, final boolean state)
  9. setBit(final int source, final int bit, final boolean value)