Here you can find the source of setBit(byte[] byteArray, int index)
public static void setBit(byte[] byteArray, int index)
//package com.java2s; //License from project: Open Source License public class Main { public static void setBit(byte[] byteArray, int index) { if (index >= byteArray.length * 8 || index < 0) { throw new ArrayIndexOutOfBoundsException(); }/*from w ww.j a va 2 s .co m*/ int arrayIndex = index / 8; index = index % 8; byte tmpByte = (byte) (0x80 >>> index); byteArray[arrayIndex] = (byte) (byteArray[arrayIndex] | tmpByte); } }