Here you can find the source of setBit(byte[] arr, int bit)
public static void setBit(byte[] arr, int bit)
//package com.java2s; public class Main { public static void setBit(byte[] arr, int bit) { int index = bit / 8; // Get the index of the array for the byte with this bit int bitPosition = bit % 8; // Position of this bit in a byte arr[index] = (byte) (arr[index] | (1 << bitPosition)); }// www . j a v a 2 s . co m }