Thread: Bit Computation

  1. #16
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Quote Originally Posted by Stoned_Coder
    never noticed how the bits go up in powers of 2??

    128 64 32 16 8 4 2 1

    Kinda suggests a use of pow() to me.
    And it was only a suggestion, theres many ways to do it. And I forgot strtoul(). Its not a function that I have ever used.
    Yes I know that, but pow is farder less efficient than bit shifting and with bit shifting the function becomes extremly simple...
    Again I'm waiting for cisokay

  2. #17
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    pow function instead of shifting? Man that must be some good stuff, Stoned.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #18
    Registered User
    Join Date
    Apr 2005
    Posts
    53
    Thank you all for your great comments and hints. I actually solved this yesterday using the nice bitset class. Though, these other methods are great as well. Thank you all.

  4. #19
    Registered User
    Join Date
    Jun 2004
    Posts
    722
    Code:
    int to_dec(char *n){
        int res=0;
        while(*n){
            res<<=1;
            res |= (*n++-'0')&1;
        }
        return res;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bit processing in C
    By eliomancini in forum C Programming
    Replies: 8
    Last Post: 06-07-2005, 10:54 AM
  2. Bit Computation Program
    By cisokay in forum C++ Programming
    Replies: 6
    Last Post: 05-13-2005, 09:32 PM
  3. Bit Manipulation Questions
    By CPPNewbie in forum C++ Programming
    Replies: 7
    Last Post: 08-12-2003, 02:17 PM
  4. Array of boolean
    By DMaxJ in forum C++ Programming
    Replies: 11
    Last Post: 10-25-2001, 11:45 PM
  5. bit conversions
    By wazilian in forum C Programming
    Replies: 4
    Last Post: 10-25-2001, 08:59 PM