Java BitSet toByteArray(BitSet bits, int sizeInBytes)

Here you can find the source of toByteArray(BitSet bits, int sizeInBytes)

Description

to Byte Array

License

Minecraft Mod Public

Declaration

public static byte[] toByteArray(BitSet bits, int sizeInBytes) 

Method Source Code


//package com.java2s;
//License from project: Minecraft Mod Public 

import java.util.BitSet;

public class Main {
    public static byte[] toByteArray(BitSet bits) {
        return toByteArray(bits, (bits.size() + 7) >> 3);
    }/*  ww w.  j a v a  2 s .  c  om*/

    public static byte[] toByteArray(BitSet bits, int sizeInBytes) {
        byte[] bytes = new byte[sizeInBytes];
        for (int i = 0; i < bits.length(); i++) {
            if (bits.get(i)) {
                bytes[i / 8] |= 1 << (i % 8);
            }
        }
        return bytes;
    }
}

Related

  1. toBitSet(String data)
  2. toBitSet(String s, int length)
  3. toByteArray(BitSet bits)
  4. toByteArray(BitSet bits)
  5. toByteArray(BitSet bits, int fixedNumBytes)
  6. toByteArray(BitSet bitSet)
  7. toByteArray(BitSet bs, int length)
  8. toFixedLengthByteArray(BitSet bs, int length)
  9. toggleInPlace(BitSet a, BitSet b)