This content has been marked as final.
Show 3 replies

1. Re: Problem with BitSet conversion to 32 bit Integer
807607 Oct 11, 2006 9:38 PM (in response to 807607)Lots of leftshifting, I would say. 
2. Re: Problem with BitSet conversion to 32 bit Integer
807607 Oct 11, 2006 11:08 PM (in response to 807607)I did the following steps, i took out the last bit set as Val, i did this shift and ORing but it wouldnt return the desired value as a 32 bit integer but i just get a single value say as "C" [where C is the value of one of the bitset] when i use outPutBig.toString(16); I then learnt from one of my colleagues that BigInteger was immutable and thats the result its not able to produce a 32 bit integer as a result of shifts and Oring. Is there any thing that needs to be modified to this code to include the 32bit conversion.
private String getHexStringFromRegister() { //m_Bitbtn.length is the number of bit sets BitSet outPutValue = m_Bitbtn[m_Bitbtn.length1].getM_Bits(); //convert this bit set to a byte array byte[] outPutValByte = BitSetUtilities.toByteArray(outPutValue); //convert to a big integer BigInteger outPutBig = new BigInteger(outPutValByte); BigInteger inPutBig; byte[] inputValByte; //m_Bitbtn.length is the number of bit sets for(int i=m_Bitbtn.length2;i>0;i){ //m_Bitbtn.getBits() will return the number of bits in the bit set "i"
inputValByte = BitSetUtilities.toByteArray(m_Bitbtn[i].getBits());
//construct a big integerinPutBig = new BigInteger(inputValByte); //left shift over the higher order bits to make room for bit field i outPutBig.shiftLeft(m_Bitbtn.msbm_Bitbtn[i].lsb);
//OR the register bit value from the bit field with outputBig integer
outPutBig = outPutBig.or(inPutBig);
}
System.out.println("outputString.toString()" +outPutBig.toString());
return outPutBig.toString();
} 
3. Re: Problem with BitSet conversion to 32 bit Integer
807607 Oct 12, 2006 1:56 AM (in response to 807607)Is that...hungarian notation?
Eww..
Since bitset grows dynamically like a vector, you can just keep adding the other bitsets to the first one.
I.e. in pseudocodefor(int i = 0;i < bs.length;i++) for(int j = 0;j < bs.length(); j++)
b.set(someIndex, bs[i].get(j));