Android Bit Set setBit(byte bits, int offset, boolean status)

Here you can find the source of setBit(byte bits, int offset, boolean status)

Description

set Bit

License

Open Source License

Declaration

public static final byte setBit(byte bits, int offset, boolean status) 

Method Source Code

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

public class Main {
    private static final byte[] ClearBits = new byte[] { (byte) 0xFE,
            (byte) 0xFD, (byte) 0xFB, (byte) 0xF7, (byte) 0xEF,
            (byte) 0xDF, (byte) 0xBF, 0x7F };

    public static final byte setBit(byte bits, int offset, boolean status) {
        if (status) {
            return setBit(bits, offset);
        } else {/*from  w w w  .jav a 2 s  .c  om*/
            return clearBit(bits, offset);
        }
    }

    public static final byte setBit(byte bits, int offset) {
        if (offset < 0 && offset > 7) {
            throw new IndexOutOfBoundsException(
                    "offset ???[0,8)??");
        }
        bits |= 0x1 << offset;
        return bits;
    }

    public static final byte clearBit(byte bits, int offset) {
        if (offset < 0 && offset > 7) {
            throw new IndexOutOfBoundsException(
                    "offset ???[0,8)??");
        }
        bits &= ClearBits[offset];
        return bits;
    }
}

Related

  1. setBit(byte bite, int offset, boolean set)
  2. resetBit(byte b, int bit)
  3. setBit(byte[] arr, int bit)
  4. setBit(byte[] bytes, int bitNr, int bit)
  5. reverseBits(byte[] bits)