-3

I have created the mysec variables for BitVector64. For the version less than 8 I would like to generate the value using the BitVector32

    static BitVector64.Section mySect1;
    static BitVector64.Section mySect2;
    static BitVector64.Section mySect3;

if (versions) > 7)
            mySect2 = BitVector64.CreateSection(14, mySect1);  // V1      - 3 bits
        else
            mySect3 = BitVector32.CreateSection(7, mySect2);

What I need now

  1. Mysect2 having value in BitVector64.Section. I need to convert explictity to BitVector32.Section and pass the aruguments.

Below converstion is not working for me

            mySect3 = BitVector32.CreateSection(7, (BitVector32.Section) mySect2);
  1. Will get the values in BItVector32.Section for mysect3 need to convert to the BitVector64.Section

Below converstion is not working for me

            mySect3 = BitVector32.CreateSection(7, (BitVector32.Section) mySect2) as BitVector34.Section;

or

   mySect3 = (BitVector64.Section) BitVector32.CreateSection(7, (BitVector32.Section) mySect2) ;
Adnan
  • 23,948
  • 17
  • 75
  • 108
Velu
  • 851
  • 4
  • 13
  • 29

1 Answers1

7

There is no type named "BitVector64" in the .NET framework. I would have to guess that you copied it from somewhere. Clearly this code you copied does not support an implicit conversion from BitVector32.Section to BitVector64.Section.

Which is unsurprising, the optimization it provides is extremely small. Rather the opposite, the conversion from uint to ulong is relatively expensive and not worth the very minor memory saving. Especially since this is a struct.

BitVector32 (and presumably BitVector64) is there explicitly to make bit manipulations fast and efficient. Faster than BitArray since it can take advantage of cpu register operations. Don't make it slow.

Hans Passant
  • 873,011
  • 131
  • 1,552
  • 2,371