public static byte[] flipAllBitsInPlace(byte[] bytes,int index,int length){
  int endIndex=Math.min(bytes.length,index + length);
  for (int i=index; i < endIndex; i++) {
    bytes[i]=(byte)(bytes[i] ^ 0xff);
  }
  return bytes;
}

public static byte [ ] flipAllBitsInPlace ( byte [ ] bytes , int index , int length ) { int endIndex = Math . min ( bytes . length , index + length ) ; for ( int i = index ; i < endIndex ; i ++ ) { bytes [ i ] = ( byte ) ( bytes [ i ] ^ 0xff ) ; } return bytes ; }
this flips the bits in the range [ index , index + length ) and returns the same byte [ ] .
