Here you can find the source of intToBitSet(int value)
Parameter | Description |
---|---|
value | Value to convert. |
public static BitSet intToBitSet(int value)
//package com.java2s; //License from project: Open Source License import java.util.BitSet; public class Main { /**//from w w w.j av a2 s . c o m * Convert an integer to BitSet. * @param value Value to convert. * @return */ public static BitSet intToBitSet(int value) { BitSet bits = new BitSet(); int index = 0; while (value != 0) { if (value % 2 != 0) { bits.set(index); } ++index; value = value >>> 1; } return bits; } /** * Stores an integer number in a BitSet object. * * @param value integer number to store * @param length number of bits to use. * @return */ public static BitSet intToBitSet(int value, int length) { BitSet bits = new BitSet(length); int index = 0; while (value != 0) { if (value % 2 != 0) { bits.set(index); } ++index; value = value >>> 1; } return bits; } }