Here you can find the source of setBit(byte[] data, int pos, boolean val)
public static void setBit(byte[] data, int pos, boolean val)
//package com.java2s; //License from project: LGPL public class Main { public static void setBit(byte[] data, int pos, boolean val) { int posByte = pos / 8; int posBit = pos % 8; byte oldByte = data[posByte]; if (val) { data[posByte] = (byte) (oldByte | (1 << 7 - posBit)); } else {//from w w w. j av a 2 s . c o m data[posByte] = (byte) (oldByte | (0 << 7 - posBit)); } } }