from Bit Set to byte array - Java java.util

Java examples for java.util:BitSet

Description

from Bit Set to byte array

Demo Code


//package com.java2s;
import java.util.BitSet;

public class Main {
    public static byte[] fromBitSet(BitSet bits) {
        byte[] b = new byte[1];
        for (int i = 0; i < bits.length(); i++) {
            if (bits.get(i) == true)
                b[0] |= 1 << i;//w w  w .j  a v  a  2 s.  co  m
        }
        return b;
    }
}

Related Tutorials