Java BitSet To Byte Array bitSetToByteArray(BitSet bitSet, int bitSetLength)

Here you can find the source of bitSetToByteArray(BitSet bitSet, int bitSetLength)

Description

bit Set To Byte Array

License

Open Source License

Declaration

private static byte[] bitSetToByteArray(BitSet bitSet, int bitSetLength) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.util.BitSet;

public class Main {
    private static byte[] bitSetToByteArray(BitSet bitSet, int bitSetLength) {
        byte[] ret = bitSet.toByteArray();
        if (ret.length == bitSetLength) {
            return ret;
        }/*  ww  w .jav  a2 s  . co m*/
        byte[] finalRet = new byte[bitSetLength % 8 == 0 ? bitSetLength / 8
                : bitSetLength / 8 + 1];
        System.arraycopy(ret, 0, finalRet, 0, ret.length);
        return finalRet;
    }
}

Related

  1. bitsetToBinary(BitSet set, int n)
  2. bitSetToBinaryString(BitSet b, int startBit, int length)
  3. bitSetToBinaryString(BitSet strainBitSet)
  4. bitSetToByteArray(BitSet bitSet, int byteLen)
  5. bitSetToByteArray(final BitSet bitSet, final int numBytes)
  6. bitSetToBytes(BitSet bs)