CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Jun 2007
    Posts
    54

    Need Ideas for this problem please thanks!

    Hi all,

    I have a C++ program which sort of displays a questinnaire to the user .........These q's are sort of yes/no questions. I am currently using bits to represent the answers they chose .... like 0 - indicates No, and 1 - indicates Yes. For this Im using an integer (32bits) ... so i can atmost make use of 32 answres(like each bit representing a questions..).....but what if I need to specify more than 32 ? Are there any other easy ways of representing these selections?

    I was wondering how to go about doing tht? Any ideas or insights is really helpful.

    Thanks all!

  2. #2
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Need Ideas for this problem please thanks!

    You can use a container of bools instead. It may or may not be less space efficient, but it certainly is less limiting than using the bits of an int.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  3. #3
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Need Ideas for this problem please thanks!

    Quote Originally Posted by harrypotter28685
    Hi all,

    I have a C++ program which sort of displays a questinnaire to the user .........These q's are sort of yes/no questions. I am currently using bits to represent the answers they chose .... like 0 - indicates No, and 1 - indicates Yes. For this Im using an integer (32bits) ... so i can atmost make use of 32 answres(like each bit representing a questions..).....but what if I need to specify more than 32 ? Are there any other easy ways of representing these selections?

    I was wondering how to go about doing tht? Any ideas or insights is really helpful.

    Thanks all!
    With memory typically in the hundreds of megabytes or gigabytes these days, why bother twiddling bits. Back in the old days when you had 100 users fighting over 1 MB of shared RAM, that made sense. Not any more.

  4. #4
    Join Date
    Jun 2007
    Posts
    54

    Re: Need Ideas for this problem please thanks!

    Yes, but wouldnt making use of bits make it faster?
    I can do shift operations etc to get a specific value faster? Inst it? Correct me if Im wrong,,Thanks!

  5. #5
    Join Date
    Jan 2006
    Location
    Singapore
    Posts
    6,765

    Re: Need Ideas for this problem please thanks!

    Yes, but wouldnt making use of bits make it faster?
    I can do shift operations etc to get a specific value faster? Inst it? Correct me if Im wrong,,Thanks!
    No it would not.
    C + C++ Compiler: MinGW port of GCC
    Build + Version Control System: SCons + Bazaar

    Look up a C/C++ Reference and learn How To Ask Questions The Smart Way
    Kindly rate my posts if you found them useful

  6. #6
    Join Date
    Aug 2000
    Location
    New York, NY, USA
    Posts
    5,656

    Re: Need Ideas for this problem please thanks!

    Quote Originally Posted by harrypotter28685
    Yes, but wouldnt making use of bits make it faster?
    It depends on what are you going to do with those bits.
    For example, you can check if all answers are correct in one statement.
    Vlad - MS MVP [2007 - 2012] - www.FeinSoftware.com
    Convenience and productivity tools for Microsoft Visual Studio:
    FeinWindows - replacement windows manager for Visual Studio, and more...

  7. #7
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Location
    Florida
    Posts
    12,637

    Re: Need Ideas for this problem please thanks!

    Quote Originally Posted by harrypotter28685
    Yes, but wouldnt making use of bits make it faster?
    I can do shift operations etc to get a specific value faster? Inst it? Correct me if Im wrong,,Thanks!
    Sam answer applies. With processor speeds in the gigahertz, who cares?

    There are times when you need to be concerned with optimizing for speed and memory efficiency. This doesn't appear to be one of them.

    FWIW, you wouldn't be doing shifting operations, you'd be doing logical ands to check individual bits.
    Last edited by GCDEF; July 31st, 2008 at 01:14 PM.

  8. #8
    Join Date
    Jan 2008
    Location
    California, USA
    Posts
    822

    Re: Need Ideas for this problem please thanks!

    From what I understand, a bit is the smallest unit an information can be stored (+/-). So I think you are right about using bits to represent your yes/no but I don't think you can go lower than bits. Like laserlight said, you can use a container of bools or std::bitset.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured