C#之网络字节序与主机字节序互转

主机字节序转网络字节序

//加上两个字节长度,再发送
 byte[] bSend = new byte[buffer.Length + 2];
byte[] bLenth = BitConverter.GetBytes((ushort)IPAddress.HostToNetworkOrder((short)buffer.Length));
bSend[0] = bLenth[0];
bSend[1] = bLenth[1];

网络字节序转主机字节序

byte[] bLenth = new byte[2];
bLenth[0] = m_listRecbuf[0];
bLenth[1] = m_listRecbuf[1];

ushort iLenth = (ushort)IPAddress.NetworkToHostOrder((short)BitConverter.ToUInt16(bLenth, 0));

猜你喜欢

转载自blog.csdn.net/g0415shenw/article/details/82224863
今日推荐