Faster way to swap endianness in C# with 16 bit words
问题 There's got to be a faster and better way to swap bytes of 16bit words then this.: public static void Swap(byte[] data) { for (int i = 0; i < data.Length; i += 2) { byte b = data[i]; data[i] = data[i + 1]; data[i + 1] = b; } } Does anyone have an idea? 回答1: In my attempt to apply for the Uberhacker award, I submit the following. For my testing, I used a Source array of 8,192 bytes and called SwapX2 100,000 times: public static unsafe void SwapX2(Byte[] source) { fixed (Byte* pSource = &source