Here you can find the source of padToByteBoundary(BitSet actualParameter, int sizeInBits, int byteBoundLength, boolean preserveFirstAsSign)
public static BitSet padToByteBoundary(BitSet actualParameter, int sizeInBits, int byteBoundLength, boolean preserveFirstAsSign)
//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; } }