Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Well here is an easy one... 1

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
It is kinda simple but the harder I try the more I confuse myself with bitset...... well I know a bitset is a set of bits.... but what does it do???


Thanks,
 
That's a really open ended question, could you be a little more specific.

A little general (probably too much so...)

A bit is the smallest amount of storage, at the machine level, it is either a signal or not, but programmers need only concern themselves by thinking of them as 1 or 0. Therefore, a byte (8 bits) can be thought of as something like:

10010011

This can be use to represent some arbitrary value, depending on the constraints we set up.

This will also delve into base-2 math and other things, so you need to post specifically what you want to know, or go get a book on binary/octal/hex stuff and look at it.

MWB.
Disclaimer:
Beware: Studies have shown that research causes cancer in lab rats.
 
It's a class for storing and manipulating a sequence of bits :) ... Now, doesn't that clear things up?

I'm not clear either where your misunderstanding lies. Do you not understand the purpose of bits? Base 2 math? How to use the class? The bit operators? Everything? Post again so we know where you're confused.

One doubt in mbaranski's post:

I know in C, a byte is not necessarily 8 bits. The number of bits in a byte is equal to CHAR_BIT (in <limits.h>). I'm pretty sure that this is true in C++ as well - CHAR_BIT is found in <climits> instead as it inherits this macro from C.

Russ
bobbitts@hotmail.com
 
Gee, I'm really late,
. . . but I figured somebody might search for this as I did and find the responses a little pale to their tastes. I don't know that this answer deserves a whole FAQ, but I think the question deserves at least this much respect:

A bitset is a container object (at one time included in the STL or Standard Template Library, but I haven't kept up with the C++ standard, so I don't know whether it's still there . . . ) that holds a structure for a string of bits. In some ways, &quot;string of bits&quot; is appropriate, in other ways it isn't: Some implementations (one of the standards, anyway) provide for access to the internal structure as a string so that it may be printed, and in many implementations passed to the template as a string initializer. As the previous contributors have suggested, it can be thought of as a string of 1's and 0's (although we only had l's O's and /'s when I started), but it represents the off/on or high/low position of a series of bits that are often used for a series of &quot;switches,&quot; or booleans that can be thought of as the result or the precursors to some decision(s).

The way a bitset is implemented matters -- particularly in terms of how much space you will save over using a set of booleans or another &quot;choice structure.&quot; Booleans are generally (though not always) implemented as a full byte (but could be as large as a word in order to use a single register). It is hard to know whether a compiler builder will economize and offer you a byte in which bits will be allocated for booleans, but the economy just doesn't seem to work with the complexity of writing a compiler, so I'd guess it isn't often seen. For this reason you will often see C-code inserted using bitfields (which are often implemented using an unsigned word).

A bitset offers you the flexibility of doing many of the same things with all the adornments of a &quot;standard&quot; template container: Implementation invisible to those who don't care and member functions that manipulate it in a convenient way.

I hope this helps somebody: I probably educated myself a little in trying to write something that would hold in the lion's share of cases.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top