Click to See Complete Forum and Search --> : Need Ideas for this problem please thanks!


harrypotter28685
July 31st, 2008, 12:47 PM
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!

laserlight
July 31st, 2008, 12:54 PM
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.

GCDEF
July 31st, 2008, 12:56 PM
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.

harrypotter28685
July 31st, 2008, 01:01 PM
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!

laserlight
July 31st, 2008, 01:04 PM
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.

VladimirF
July 31st, 2008, 01:11 PM
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.

GCDEF
July 31st, 2008, 01:12 PM
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.

potatoCode
July 31st, 2008, 01:31 PM
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.