Re: Crash when using bitset

From: Henrik Stuart (hstuart@geocities.com)
Date: 02/09/02


Greetings,

On Saturday, February 09, 2002 3:57:33 PM Karl B Buchner wrote:
>>    Well, your problem is pretty straightforward:
>>    You have 8 bits and you're trying to see whether number 16 is
>> set.

> So flags.test(x) will test (1<<x), and not x?

   test will test whether bit number x is set. Whether it does this by
   looking at (1 << x) internally or not is of little interest. :o)

> What about |= operator and such?

   operator |= takes a right-hand side of const bitset<bits>& so it
   OR's two bitsets of comparative size.
   As for the other they are quite nicely listed in the standard and
   in a lot of books pertaining to the standard library [1].

> In other words, do some of the bitset funcs and operators
> take the number of the bit and others the bit itself?

   No, they all take either the number of the bit or another bitset.

> if i wanted to test both bit #4 and bit #5 would i have
> to do two checks (flags.set(4) || flags.set(5)) instead of
> the one for standard bitvectors (IS_SET((1 << 4) | (1 << 5)))?

   Well, I hope that you'd test rather than set the bits to see
   whether they are set. :o)

   if (flags.test(4) || flags.test(5))

   is the same as

   if (IS_SET(flags, (1 << 4)) || IS_SET(flags, (1 << 5)))

> sorry if its a bit question laden, but I'm prety new to c++

   See [1]. :o)

[1]: A good and thorough reference is always a must when you try to
delve into some topic, particularly C++ as it isn't too trivial. :o)
So I'd recommend picking up at least the following two books:
Stroustrup, Bjarne: The C++ Programming Language, 3rd. Edition
Josuttis, Nicolai M.: The C++ Standard Library: A Tutorial and
Reference
Some might differ in their preference for a standard library
reference, others might argue that Stroustrup gives an adequate
introduction to the standard library, but in my opinion, Josuttis give
a nice and complete introduction to using the standard c++ library in
terms understandable for people at the beginning stages through to
more advanced programmers.

--
Yours truly,
  Henrik Stuart (http://www.unprompted.com/hstuart/)

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   | Newbie List:  http://groups.yahoo.com/group/circle-newbies/   |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 06/25/03 PDT