Here you can find the source of setBit(byte v, int position, boolean value)
public static byte setBit(byte v, int position, boolean value)
//package com.java2s; //License from project: Apache License public class Main { /**/*ww w .ja v a 2 s. c om*/ * Returns v, with the bit at position set to 1 or 0 depending on value. */ public static byte setBit(byte v, int position, boolean value) { return (byte) setBit((int) v, position, value); } public static short setBit(short v, int position, boolean value) { return (short) setBit((int) v, position, value); } public static int setBit(int v, int position, boolean value) { if (value) return v | (1 << position); else return clearBit(v, position); } public static long setBit(long v, int position, boolean value) { if (value) return v | (1L << position); else return clearBit(v, position); } /** * Returns v, with the bit at position set to zero. */ public static byte clearBit(byte v, int position) { return (byte) clearBit((int) v, position); } public static short clearBit(short v, int position) { return (short) clearBit((int) v, position); } public static int clearBit(int v, int position) { return v & ~(1 << position); } public static long clearBit(long v, int position) { return v & ~(1L << position); } }