Here you can find the source of setBit(final long word, final int idx, final boolean bit)
public static long setBit(final long word, final int idx, final boolean bit)
//package com.java2s; //License from project: Open Source License public class Main { public static long setBit(final long word, final int idx, final boolean bit) { if (bit)/*from w w w. ja va 2 s . c o m*/ return setBitTo1(word, idx); return setBitTo0(word, idx); } private static long setBitTo1(final long word, final int idx) { return ((1l << idx) | word); } private static long setBitTo0(final long word, final int idx) { return (~(1l << idx) & word); } }