Convert a bitset to a BigInteger. - Java java.util

Java examples for java.util:BitSet

Description

Convert a bitset to a BigInteger.

Demo Code


//package com.java2s;
import java.util.*;
import java.math.*;

public class Main {
    /**//from ww  w. jav a2s. c o  m
     * Convert a bitset to a BigInteger.
     * 
     * @param bs The bitset.
     * 
     * @return the corresponding BigInteger.
     */
    public static BigInteger ToBigInteger(BitSet bs) {

        BigInteger value = BigInteger.ZERO;
        for (int i = 0; i < bs.length(); i += 1) {
            if (bs.get(i))
                value = value.setBit(i);
        }
        return value;
    }
}

Related Tutorials