The magic is used to compare against constants. As it isn't a number it isn't in a big endian or little endian format. You should just use the constants to either set or compare the values; they do not necessarily need to contain any number.
The length is an ULONG and since .NET unfortunately is based on little endian it is undoubtedly also stored as little endian. Normally you don't care; just use an ULONG to set or retrieve it.
If you have a BigInteger
instance then you can simply save it as bytes using ToByteArray
and then reverse the order of the bytes. The bits inside will stay the same. If the value has a zero byte to the left (after reversing) then you need to strip that byte as well.