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