Here you can find the source of setBit(byte bits, int offset, boolean status)
public static final byte setBit(byte bits, int offset, boolean status)
//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; } }