Here you can find the source of flipBits(byte[] bytes, int start, int bitLength)
public static void flipBits(byte[] bytes, int start, int bitLength)
//package com.java2s; //License from project: Open Source License public class Main { public static void flipBits(byte[] bytes, int start, int bitLength) { for (int i = 0; i < bitLength / 2; i++) { boolean leftBit = getBit(bytes, start * 8 + i); boolean rightBit = getBit(bytes, start * 8 + bitLength - i - 1); setBit(bytes, start * 8 + i, rightBit); setBit(bytes, start * 8 + bitLength - i - 1, leftBit); }//from w w w.j av a2 s . co m } public static boolean getBit(byte[] bytes, int off) { byte b = bytes[off / 8]; return (b & (0x01 << (off % 8))) != 0; } public static void setBit(byte[] bytes, int off, boolean v) { if (v) bytes[off / 8] |= (0x01 << (off % 8)); else bytes[off / 8] &= ~(0x01 << (off % 8)); } }