How to extract selective bits from BitArray

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I have a BitArray that contains a value --> 1011001 (89)

I want to extract four bits (bits 0-3) of the BitArray --> 1011 (11)

Is there an easy way to do this that I'm missing? Or would I have to create
another BitArray and iterate through the 4 bits of the original BitArray that
I want and copy them one by one?


Thanks,
skicow
 
What's a bit array? And what language?

In C#, if I use an int as a group of bits, I use:

int x = y & 0x0F ;
 
PIEBALD said:
What's a bit array? And what language?

In C#, if I use an int as a group of bits, I use:

int x = y & 0x0F ;

A BitArray is a VB.NET class that is used to easily store a collection of
bits - it's a lot like a Boolean Array really. But it also allows you to
manipulate the bits within quite easily, e.g. bitwise comparisons to the bits
in the Bitarray.

So if in C# you had an integer like so:

int x = 20 //10100

How would you get the 3 LSB's? (100) out of x and into another int variable?
Convert the binary representation of the int to a string and then substring
it?

Thanks,
skicow
 
Back
Top