Java BitSet padToByteBoundary(BitSet actualParameter, int sizeInBits, int byteBoundLength, boolean preserveFirstAsSign)

Here you can find the source of padToByteBoundary(BitSet actualParameter, int sizeInBits, int byteBoundLength, boolean preserveFirstAsSign)

Description

pad To Byte Boundary

License

Apache License

Declaration

public static BitSet padToByteBoundary(BitSet actualParameter, int sizeInBits, int byteBoundLength,
            boolean preserveFirstAsSign) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

import java.util.BitSet;

public class Main {
    public static BitSet padToByteBoundary(BitSet actualParameter, int sizeInBits, int byteBoundLength,
            boolean preserveFirstAsSign) {
        BitSet paddedSet = new BitSet(byteBoundLength);
        int numPaddingBits = byteBoundLength - sizeInBits;

        // If we are preserving the sign and the first bit is set
        if (preserveFirstAsSign && actualParameter.get(0)) {
            for (int i = 0; i < numPaddingBits; i++) {
                paddedSet.set(i);/*from  www. j  a v  a  2s.c  o m*/
            }
        }

        for (int i = numPaddingBits; i < byteBoundLength; i++) {
            if (actualParameter.get(i - numPaddingBits)) {
                paddedSet.set(i);
            }
        }

        return paddedSet;
    }
}

Related

  1. members(BitSet set)
  2. nextClearBitModulo(int index, int poolSize, BitSet bitSet)
  3. not(BitSet bitSets)
  4. or(BitSet bs1, BitSet bs2)
  5. pack(BitSet bitSet)
  6. parseBitSet(byte[] sfData, int offset, int length)
  7. pickRandomSetIndexFromBitSet(BitSet bitset)
  8. printBitSet(BitSet bs)
  9. printBitSet(BitSet iBits, int length)