"A. H." wrote:
> I have a little problem with CVI. I'm trying to check that a data
> I read is a power of two or if it isn't but I don't know exactly how to do
> this.
> Is there any function that tells if a data is a power or two? I hope anybody
> could help me!!
Here's how I would do it:
Advantages: All integer, no slow floating-point logarithms with their
round-off error poblemss. Theory: An integer is a power of two if it
has exactly one bit in its binary representation.
int isPowerOfTwo(int i) {
int sum;
for (sum=0; i>0; i>>=1) sum += i&1;
return sum==1;
}
Hope this helps!
- Rich