-
BitCount() Issue
Perhaps I'm misunderstanding the purpose of BitCount. I thought that it would return the number of bits needed to represent the current value held in a variable. Is this correct?
I'm trying to write a simulator but certain registers can't be over 24 bits or 48 bits. Hm, well, closest I have to that are Integers and Longs.
Here's the function checking:
Code:
public void SetValue(long val){
System.out.println(" bitCount: " + Long.bitCount(val));
if(Long.bitCount(val) > bitNum){
System.out.println("Too many bits! bitCount: " + Long.bitCount(val) + " > " + bitNum);
}
else{
value = val;
}
}
And here's my output:
Code:
//In the test program I set the initial value to 3. The max number of bits
//is also 3, for testing simplicity.
bitCount: 2
Reg Value: 3
Input really big number:
25
bitCount: 3
Reg Value: 25
Nevermind--I found my answer elsewhere.
-
So that, it's better to post your solution over here. It may helpful for others as well. And also if you've solve the problem then please mark the thread solved.