byte操作

zgke 2008-12-23 11:39:11
byte[] _Bytes = new byte[3];
_Bytes[0] = 2; // 00000010
_Bytes[1] = 3; // 00000011
_Bytes[2] = 4; // 00000100



byte[] _ReverseBytes =new byte[3];
_ReverseBytes[0] = 64; // 01000000
_ReverseBytes[1] = 192; // 11000000
_ReverseBytes[2] = 32; // 00100000

怎么实现 _Bytes反转的 不想用Convert.ToString()方法来转.这个BYTE数据太大了.
...全文
129 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
zgke 2008-12-23
  • 打赏
  • 举报
回复
谢谢

_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 0) & 0x01) << 7);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 1) & 0x01) << 6);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 2) & 0x01) << 5);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 3) & 0x01) << 4);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 4) & 0x01) << 3);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 5) & 0x01) << 2);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 6) & 0x01) << 1);
_ReverseBytes[0] |= (byte)(((_Bytes[1] >> 7) & 0x01) << 0);

是不是这个也可以?
jxxx2967 2008-12-23
  • 打赏
  • 举报
回复

for(int i = 0; i < 8; i++)
{
_ReverseBytes[0] |= ((_Bytes[0] >> i) & 0x01)<<(7-i);
}
zgke 2008-12-23
  • 打赏
  • 举报
回复
就是反转 byte 00000010 ---> 01000000

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧