Introduction
Some applications of signal processing, like Fast Fourier Transform (FFT) need the length of sampled-data
input equal to 2^n (where n : integer, n=1,2,3,...), and requires fast testing for this number. This test
must be done in a very short time especially in real-time applications operated in DSP cart (as in TMS320C6xxx DSP).
Here is an optimized code snippet for this purpose.
Source code
The following function return TRUE
if the number x has the form 2^n
bool CheckInputToFFT(int x)
{
return (!(x & (x-1)));
}
That's all, which means each of the numbers (2,4,8,16,...2^n) gives zero when ANDed with previous number!