Java examples for java.util:BitSet
get BitSet From Char
//package com.java2s; import java.util.BitSet; public class Main { public static void main(String[] argv) throws Exception { char value = 'a'; int size = 2; System.out.println(getBitSetFromChar(value, size)); }/*from w w w. j a va 2 s. c om*/ public static BitSet getBitSetFromChar(char value, int size) { BitSet bits = new BitSet(size); boolean bitValue; int index = 0; while (value > 0) { if ((value % 2) == 0) { bitValue = false; } else { bitValue = true; } bits.set(index++, bitValue); value /= 2; } return bits; } }