bit pattern question

J

jason

is there a way to set up an array of bits of generic size, cycle
through all the possible bit patterns, and detect a sub-pattern within
the bit pattern?

for cycling through possible patterns: i was thinking of just using an
unsigned int that increments for the cycling of bit patterns, but those
only come in prescribed sizes. i was hoping for something more generic,
that would allow for a 10bit pattern, for example.

for the sub-pattern analysis: i was hoping to analyze each bit pattern,
and be able to answer questions like "how many bits are 1 in this
pattern?" and "are there three bits in a row that are 1 in this
pattern?"

i can cludge something together using string manipulation, but that
will be much larger, and i'm guessing much slower, than bit pattern
manipulation. any ideas of what i could use for a bit pattern solution?

thanks,

jason
 
J

jason

for the cycling: actually, now that i think about it, i guess i could
just use the largest non-floating numeric type, and control how large
the value could get with the loop constraints. that would, in effect,
give me a bit pattern of arbitrary size, up to the maximum size of the
datatype. that would work. so i guess my only question now is about the
sub-pattern analysis.

thanks,

jason
 
J

jason

thanks! this loooks good. quick question though. is there a way to
increment the binary pattern that the bit array makes? i didn't notice
anything built into the class that would do it.

i suppose could still use an integer to increment, and then pass that
integer value into the constructor of a BitArray for pattern analysis.
but i wasn't sure if there was a BitArray incrementer hidden somewhere,
since that seems like it would be useful!

thanks again,

jason
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top