Java BitSet reverseBitSet(BitSet bs)

Here you can find the source of reverseBitSet(BitSet bs)

Description

Noddy method to reverse a BitSet.

License

Open Source License

Parameter

Parameter Description
bs a parameter

Declaration

public static BitSet reverseBitSet(BitSet bs) 

Method Source Code

//package com.java2s;
/* Image to ZX Spec/*ww  w. j  a v  a2 s.  c  o  m*/
 * Copyright (C) 2014 Silent Software (Benjamin Brown)
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */

import java.util.BitSet;

public class Main {
    /**
     * Noddy method to reverse a BitSet. 
     * Basically this is just to fix the endianness of
     * the image bytes.
     * 
     * @param bs
     * @return
     */
    public static BitSet reverseBitSet(BitSet bs) {
        final BitSet copy = new BitSet(8);
        int counter = 0;
        int size = bs.length();
        for (int i = 0; i < size; ++i) {
            if (i % 8 == 0 && i != 0) {
                for (int j = 8; j >= 1; j--) {
                    bs.clear(i - j);
                    if (copy.get(j - 1)) {
                        bs.set(i - j);
                    }
                }
                copy.clear();
                counter = 0;
            }
            if (bs.get(i)) {
                copy.set(counter);
            }
            ++counter;
        }
        return bs;
    }
}

Related

  1. pickRandomSetIndexFromBitSet(BitSet bitset)
  2. printBitSet(BitSet bs)
  3. printBitSet(BitSet iBits, int length)
  4. readByte(BitSet bits, int startByte)
  5. reverse(final BitSet bitset, final int sizeInBits)
  6. setBitIterator(final BitSet b)
  7. setBits(BitSet bitSet, Iterable indexes)
  8. setBitSet(BitSet bitSet, int x1, int x2, int y, int width)
  9. shiftLeft(BitSet bs, int n)