Here you can find the source of reverseBitSet(BitSet bs)
Parameter | Description |
---|---|
bs | a parameter |
public static BitSet reverseBitSet(BitSet bs)
//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; } }