Convert a BitSet to a string representation in the specified radix. - Java java.util

Java examples for java.util:BitSet

Description

Convert a BitSet to a string representation in the specified radix.

Demo Code


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

public class Main {
    /**/*from   www  . jav  a2 s.  c om*/
     * Convert a BitSet to a string representation in the specified radix.
     * 
     * @param bs The BitSet to convert.
     * @param radix The radix to convert the BitSet to.
     * 
     * @return A string representation of the BitSet in the specified radix.
     */
    public static String ToString(BitSet bs, int radix) {

        BigInteger bi = BigInteger.ZERO;

        for (int index = bs.nextSetBit(0); index >= 0; index = bs
                .nextSetBit(index + 1)) {
            bi = bi.setBit(index);
        }

        return bi.toString(radix).toUpperCase();
    }
}

Related Tutorials