Question How to pass a bitarray to a function

spach

Member
Joined
Sep 25, 2006
Messages
5
Programming Experience
Beginner
I'm trying to pass 2 bitarrays to a function that ANDs the bitarrays and returns the count of bits that are set to TRUE.
However, something strange happens when I reference the bitarray from within the function and the results are non-sensical.

So I have output the bitarray contents before it is passed to the functionand they match the source data, then I output the contects of the bitarray from within the functiona and they are completely different.

I can't figure out for the life of me what's happening? Any help on this would be greatly appreciated.
 
Passing an object around doesn't change it. One possible cause could be that you are looking at the values after they have been changed by the BitArray methods, all the bitwise methods changes the current instance.
 
Hi JohnH,

Many thanks for your reply.

I foolishly thought that if I passed the object into a function BYVAL, then the object properties would not be altered.

Of course this is not the case with objects and you were absolutely correct in that the bitwise methods had altered the original bitarray hence the differing values that were returned during subsequent calculations.

I have circumvented this by cloning the bitarrays and passing the clones to the function - works perfectly and is extremely fast!

Once again, Many thanks for the reply!
 
Back
Top