|
-
July 31st, 2008, 12:47 PM
#1
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!
-
July 31st, 2008, 12:54 PM
#2
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.
-
July 31st, 2008, 12:56 PM
#3
Re: Need Ideas for this problem please thanks!
 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.
-
July 31st, 2008, 01:01 PM
#4
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!
-
July 31st, 2008, 01:04 PM
#5
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.
-
July 31st, 2008, 01:11 PM
#6
Re: Need Ideas for this problem please thanks!
 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...
-
July 31st, 2008, 01:12 PM
#7
Re: Need Ideas for this problem please thanks!
 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.
-
July 31st, 2008, 01:31 PM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|