Here you can find the source of swap(byte[] data, int p, int q)
private static void swap(byte[] data, int p, int q)
//package com.java2s; /**//from w ww. j a v a 2 s. c o m * Project: com.dianping.lion.lion-console-0.0.1 * * File Created at 2012-7-15 * $Id$ * * Copyright 2010 dianping.com. * All rights reserved. * * This software is the confidential and proprietary information of * Dianping Company. ("Confidential Information"). You shall not * disclose such Confidential Information and shall use it only in * accordance with the terms of the license agreement you entered into * with dianping.com. */ public class Main { private static void swap(byte[] data, int p, int q) { int len = data.length * 8; for (int i = 0; i < len; i += p) { int j = i + q; if (j < len) { byte b1 = data[i / 8]; byte b2 = data[j / 8]; int f1 = b1 & (1 << (i % 8)); int f2 = b2 & (1 << (j % 8)); if ((f1 != 0) != (f2 != 0)) { data[i / 8] ^= 1 << (i % 8); data[j / 8] ^= 1 << (j % 8); } } } } }