I've done some digging and I didn't find a solution to my question yet. I want to take a decimal number and turn it into bits. Then i want to analyze the bits and determine the highest bit. For example, 8 is represented as 1000 in binary. The most significant bit is in the 2^4 position. The best solution I have found is to do something like
int temp=8;
bitset<32> binary;
binary=temp;
int pos;
for (int i=32;i>=0;i--){
if (binary[i]==1) {
pos=i;
break;
}
}
but I am wondering if there is any better solution to this? Is there a way to not include the leading zeros and just have the binary number be 1000 instead of 00....1000? The value in temp could be any number containing 32 bits.