Here you can find the source of setBits(byte in, byte data, int position, int fillBits)
public static byte setBits(byte in, byte data, int position, int fillBits)
//package com.java2s; public class Main { public static byte setBits(byte in, byte data, int position, int fillBits) { if (position - fillBits == 0) { fillBits++;//from ww w . j a va 2 s .com } in |= data << 9 - position - fillBits; return in; } public static short setBits(short in, short data, int position, int fillBits) { if (position - fillBits == 0) { fillBits++; } in |= data << 17 - position - fillBits; return in; } }