need explanation

This is a discussion on need explanation within the C Programming forums, part of the General Programming Boards category; I 'm trying to read and understand code for calculating FFT, I'm having problems with understanding this part: Code: m ...

  1. #1
    Registered User Micko's Avatar
    Join Date
    Nov 2003
    Posts
    712

    need explanation

    I 'm trying to read and understand code for calculating FFT, I'm having problems with understanding this part:
    Code:
    	m = int(log(Len)/log(2.0));
    	int Radix2 = 1 << m;  // find nearest radix-2 length
    	if (Radix2 != Len) {
    		return(-1);
    	}
    but I don't know what 1<<m means?
    Thanks!

  2. #2
    Registered User
    Join Date
    May 2004
    Posts
    12

  3. #3
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >but I don't know what 1<<m means?
    It means to shift the binary value of 1 to the left by m bits and fill the vacated bits with 0. Assuming 8 bits for simplicity, here is the progression of m being 0 to 6:
    Code:
    1 == 0000001
    
    m = 0: 0000001
    m = 1: 0000010
    m = 2: 0000100
    m = 3: 0001000
    m = 4: 0010000
    m = 5: 0100000
    m = 6: 1000000
    Notice the pattern? Apply that to the rest of the algorithm and see what you come up with.
    My best code is written with the delete key.

  4. #4
    Registered User
    Join Date
    Jul 2004
    Posts
    6
    what is this int(expr) function?
    did you mean to type (int) expr ?

  5. #5
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    int(expression) is another form of casting. While I haven't seen it in C I have seen it in C++

  6. #6
    CS Author and Instructor
    Join Date
    Sep 2002
    Posts
    511
    Agree with Prelude;

    Also, when shifting to the left you are actually multiplying by a power of 2 each time.

    Notice the pattern Prelude spelled out.
    Mr. C: Author and Instructor

  7. #7
    Code Goddess Prelude's Avatar
    Join Date
    Sep 2001
    Posts
    9,796
    >While I haven't seen it in C I have seen it in C++
    That's because it isn't legal C.
    My best code is written with the delete key.

  8. #8
    & the hat of GPL slaying Thantos's Avatar
    Join Date
    Sep 2001
    Posts
    5,681
    That would explain why I hadn't seen it in C before

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Linked Lists
    By Bleu_Cheese in forum C++ Programming
    Replies: 13
    Last Post: 12-21-2007, 08:17 PM
  2. printf function explanation
    By vice in forum C Programming
    Replies: 3
    Last Post: 09-21-2005, 08:35 PM
  3. Explanation
    By fallonides in forum C Programming
    Replies: 3
    Last Post: 03-19-2003, 12:41 PM
  4. basic linked list declaration..need explanation
    By aspand in forum C Programming
    Replies: 3
    Last Post: 06-07-2002, 05:55 PM
  5. Explanation!!!
    By MITCHELL in forum Windows Programming
    Replies: 4
    Last Post: 10-25-2001, 01:13 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21