bitset

Rupert Wood me@rupey.net
Thu Jul 10 11:25:00 GMT 2008


Rudra Banerjee wrote:

> bitset<bit> i (0);*(i.e. to read the bit as an integer variable)

No, what you're actually saying there is "define i as a bitset container for 'bit' bits". Since 'bit' can vary at runtime the compiler won't let you do this.

I don't know bitsets but looking at the docs to access bit x of a bitset container b you can use:

    b.test(x)

To test bit x of an integer i without using bitsets you can use:

    if ((i && (1 << x)) != 0)

or similar. Note that if i is something other than an integer you'll need a type suffix on the 1 in that expression, e.g. 1LL for long longs.

Hope that helps!
Rup.



More information about the Gcc-help mailing list