Here you can find the source of setBit(byte[] data, int pos, int val)
public static void setBit(byte[] data, int pos, int val)
//package com.java2s; //License from project: Apache License public class Main { public static void setBit(byte[] data, int pos, int val) { int posByte = pos / 8; int posBit = pos % 8; byte oldByte = data[posByte]; oldByte = (byte) (((0xFF7F >> posBit) & oldByte) & 0x00FF); byte newByte = (byte) ((val << (8 - (posBit + 1))) | oldByte); data[posByte] = newByte;//from ww w. j ava 2 s .c om } }