Click here to Skip to main content
12,633,073 members (31,307 online)
Click here to Skip to main content
Add your own
alternative version

Stats

56.3K views
25 bookmarked
Posted

Fast Algorithm to check the numbers 2^n

, 12 Dec 2002
Rate this:
Please Sign up or sign in to vote.
Optimised code for valid data length to FFT

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!

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

zarzor
Web Developer
Hong Kong Hong Kong
Still alive

You may also be interested in...

Pro

Comments and Discussions

 
GeneralC# Trick Pin
KK Adams30-Jun-08 17:12
memberKK Adams30-Jun-08 17:12 
GeneralRe: C# Trick Pin
Member 150696612-Jun-09 10:36
memberMember 150696612-Jun-09 10:36 
GeneralMod - Works for n = 0 Pin
st0le18-Feb-08 20:04
memberst0le18-Feb-08 20:04 
GeneralFFT in Visual C++ Pin
Anonymous7-Jul-03 2:18
sussAnonymous7-Jul-03 2:18 
GeneralQuick Mod for 2^0 and others Pin
Colin Davies27-Dec-02 15:16
memberColin Davies27-Dec-02 15:16 
GeneralRe: Quick Mod for 2^0 and others Pin
nutty21-Mar-06 7:23
membernutty21-Mar-06 7:23 
GeneralThanks... Pin
Rocky1010-Dec-02 4:36
memberRocky1010-Dec-02 4:36 
GeneralHacker's Delight by Warren Pin
George V. Reilly9-Dec-02 16:58
memberGeorge V. Reilly9-Dec-02 16:58 
GeneralMake it slightly faster... Pin
KevinHall5-Dec-02 19:08
memberKevinHall5-Dec-02 19:08 
GeneralHmmm.... Pin
Nitron5-Dec-02 18:38
memberNitron5-Dec-02 18:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161208.2 | Last Updated 13 Dec 2002
Article Copyright 2002 by zarzor
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid