Does BitArray endianess always match BitConverter endianess?

145 Views Asked by At

If my class uses the BitArray and BitConverter classes, will the endianess of both always match?

The documentation for the BitConverter constructor explicitly mentions that it depends on the architecture it is being used on (so nearly always little-endian), however the BitArray(Byte) constructor documentation just says:

The first byte in the array represents bits 0 through 7, the second byte represents bits 8 through 15, and so on

But this does not specify if the endianess scheme holds for using BitArray.CopyTo(), for example.

EDIT

An example where this might matter is:

Dim MyBitArray As BitArray = New BitArray(16, false)
'...here some values might have been assigned to the bit array...
Dim ba As Byte() = New Byte() {0, 0}
MyBitArray.CopyTo(ba, 0) 'Copy bit array to byte array
Dim x As Int16 = BitConverter.ToInt16(ba, 0)'Converter expects little endian, but did CopyTo put the bytes into the array in the right order?
0

There are 0 best solutions below