Help in finding the bitsets? 
Author Message
 Help in finding the bitsets?

I have a programming problem that I can't seem to work out and the zero(0)
bit is from left to right, instead right to left.

I need to see which bits are set with the following ...

I have 100 bits that I have to work with.

If I use the base 2, I would surely run out of decimals numbers to work
with.

           1    2   4   8 16 32 64 128 256 512 1024  ---> etc ... numbers
gets out of range! before 100th bit.
bits    00  01 02 03 04 05 06   07   08   09     10  ---> 94  96  97  98  99
100
           x               x                                  x
x                 x

Let say I have, the bits set showing as an X underneath of the bits.

Also, either way bit 0 could be far right or in this case above bit 0 is
start left.

How can this bit evaluation be done? An example would be great to show me.

Thanks so much.



Mon, 05 Jul 2004 10:08:14 GMT  
 Help in finding the bitsets?

Quote:
> I have a programming problem that I can't seem to work out and the zero(0)
> bit is from left to right, instead right to left.

I'm afraid the left-to-right or right-to-left-ness is all in your mind.

Quote:

> I need to see which bits are set with the following ...

> I have 100 bits that I have to work with.

> If I use the base 2, I would surely run out of decimals numbers to work
> with.

>            1    2   4   8 16 32 64 128 256 512 1024  ---> etc ... numbers
> gets out of range! before 100th bit.

If you're operating on a computer with at most 100-bits of total storage
then yes.

Quote:
> bits    00  01 02 03 04 05 06   07   08   09     10  ---> 94  96  97  98
99
> 100
>            x               x                                  x
> x                 x

> Let say I have, the bits set showing as an X underneath of the bits.

> Also, either way bit 0 could be far right or in this case above bit 0 is
> start left.

> How can this bit evaluation be done? An example would be great to show me.

> Thanks so much.

#include <limits.h>

unsigned char my_bits[(100 + CHAR_BIT - 1)/CHAR_BIT];

#define bitset(n)  ( my_bits[(n)/CHAR_BIT] |=   1U << ((n) % CHAR_BIT)  )
#define bitclr(n)  ( my_bits[(n)/CHAR_BIT] &= ~(1U << ((n) % CHAR_BIT)) )
#define bittst(n)  ( my_bits[(n)/CHAR_BIT] &   (1U << ((n) % CHAR_BIT)) )

--
Peter



Mon, 05 Jul 2004 18:49:25 GMT  
 Help in finding the bitsets?


Quote:


> > I have a programming problem that I can't seem to work out and the
zero(0)
> > bit is from left to right, instead right to left.

> I'm afraid the left-to-right or right-to-left-ness is all in your mind.

I believe you are absolutely correct. I've been doing C for about 3 years
now, but
never encountered doing bit checking, etc... This is my first. So, yes, I do
have my
mind in the wrong place.

Quote:

> > I need to see which bits are set with the following ...

> > I have 100 bits that I have to work with.

> > If I use the base 2, I would surely run out of decimals numbers to work
> > with.

> >            1    2   4   8 16 32 64 128 256 512 1024  ---> etc ...
numbers
> > gets out of range! before 100th bit.

> If you're operating on a computer with at most 100-bits of total storage
> then yes.

> > bits    00  01 02 03 04 05 06   07   08   09     10  ---> 94  96  97  98
> 99
> > 100
> >            x               x                                  x
> > x                 x

> > Let say I have, the bits set showing as an X underneath of the bits.

> > Also, either way bit 0 could be far right or in this case above bit 0 is
> > start left.

> > How can this bit evaluation be done? An example would be great to show
me.

> > Thanks so much.

> #include <limits.h>

> unsigned char my_bits[(100 + CHAR_BIT - 1)/CHAR_BIT];

> #define bitset(n)  ( my_bits[(n)/CHAR_BIT] |=   1U << ((n) % CHAR_BIT)  )
> #define bitclr(n)  ( my_bits[(n)/CHAR_BIT] &= ~(1U << ((n) % CHAR_BIT)) )
> #define bittst(n)  ( my_bits[(n)/CHAR_BIT] &   (1U << ((n) % CHAR_BIT)) )

Thankyou so much for the above. I see how now, but don't actually fully
understand it.
It works like a charm though. I'm sure I will eventually, get it the more I
use it.

Again, thank you so much for the examples to my problem. Now , I can make
the boss happy
to get my project completed.

-JT



Tue, 06 Jul 2004 02:09:02 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Bitset examples from the FAQ (unsigned char?)

2. libclc bitset import/export

3. libclc: bitset interface, new final vote

4. libclc: bitset interface

5. C++ to C# std::bitset

6. BITSET

7. bitsets

8. bitset

9. bitset?

10. template-Klasse bitset

11. use bitset instead

12. Compiler Error C2783 when using Bitsets.

 

 
Powered by phpBB® Forum Software