c# 字节数组翻转_在C#中翻转long的字节序

c# 字节数组翻转

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   = 00000000000101

154 = 0000001001 1010 5 = 0000000000 0101

And make it FAST...;)

并使其快速...;)

翻译自: https://www.hanselman.com/blog/flip-the-endianness-of-a-long-in-c

c# 字节数组翻转

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值