![c# 字节数组翻转](https://i-blog.csdnimg.cn/blog_migrate/1f70a8a7e0b4c7d0c38ff259191c2927.png)
c# 字节数组翻转
Programming challenge:
编程挑战:
Write me a function with this signature in C#:
用C#给我写一个带有此签名的函数:
public (unsafe?) long Reverse(long i, int bits)
public(unsafe?)long反向(long i,int位)
...to flip the endian-ness (LSB/MSB) of a long, but just the # of significant bits specified.
...翻转长整数的字节序(LSB / MSB),但仅指定有效位的#个。
Example, if the input is 376, with bits=11, the output is 244 (decimal, base 10).
例如,如果输入为376,位= 11,则输出为244(十进制,基数为10)。
376 = 00000101111000244 = 00000011110100
376 = 000 00101111000 244 = 000 00011110100
Example, if the input is 900, with bits=11, the output is 270.
例如,如果输入为900,位= 11,则输出为270。
900 = 00001110000100270 = 00000100001110
900 = 000 01110000100 270 = 000 00100001110
Example, if the input is 900, with bits=12, the output is 540.
例如,如果输入为900,位= 12,则输出为540。
900 = 00001110000100540 = 00001000011100
900 = 00 001110000100 540 = 00 001000011100
Example, if the input is 154, with bits=4, the output is 5.
例如,如果输入为154,位= 4,则输出为5。
154 = 00000010011010
5 = 00000000000101154 = 0000001001 1010 5 = 0000000000 0101
And make it FAST...;)
并使其快速...;)
翻译自: https://www.hanselman.com/blog/flip-the-endianness-of-a-long-in-c
c# 字节数组翻转