Here you can find the source of setBit(byte in, int position, boolean value)
public static byte setBit(byte in, int position, boolean value)
//package com.java2s; public class Main { public static byte setBit(byte in, int position, boolean value) { if (!value) { return (byte) (in & (0xFF ^ 1 << 8 - position)); } else {/*www.jav a 2s . c o m*/ return setBit(in, position); } } public static short setBit(short in, int position, boolean value) { if (!value) { return (short) (in & (0xFFFF ^ 1 << 16 - position)); } else { return setBit(in, position); } } public static byte setBit(byte in, int position) { in |= 1 << 8 - position; return in; } public static short setBit(short in, int position) { in |= 1 << 16 - position; return in; } }